title: how to get space as a input in String in java and use as it as null
body: <p>i m trying to get space as a input in string in java but i m facing problem. my code is </p>
  
  <p>input should be like</p>
  
  <p><strong>case one</strong></p>
  
  <pre><code>Ram Raja Gopal
  </code></pre>
  
  <p><strong>output</strong> should be </p>
  
  <pre><code>Gopal Ram Raja
  </code></pre>
  
  <p><strong>case two</strong> </p>
  
  <p><strong>input</strong></p>
  
  <pre><code>Ram  Gopal ( Ram is first name and Gopal is Last name)
  </code></pre>
  
  <p><strong>output</strong> should be </p>
  
  <pre><code>Gopal Ram
  </code></pre>
  
  <p>etc.</p>
  
  <pre><code>import java.util.Scanner;    
  
  public class abc {
  
      static Scanner z = new Scanner (System.in);
      static String f;
      static String m;
      static String s;
  public static void main(String args[])
  {   
      f= z.next();
  
      ab();
      bc();
  
      if(f!=null &amp;&amp; m!=null &amp;&amp; s!=null )
      {
  
         System.out.println(s+" "+f+" "+m);
      }
      else if(f!=null &amp;&amp; m==null &amp;&amp; s!=null)
      {
          System.out.println(s+" "+f);
      }       
      else if(f!=null &amp;&amp; m!=null &amp;&amp; s==null)
      {
          System.out.println(f+" "+m);
      }       
      else if(f!=null &amp;&amp; m==null &amp;&amp; s==null)
      {
          System.out.println(f);
      }   
  }
  
  public static String ab()
  {
      m=z.next();
      if(z.next().equals(" "))
      {
          m=null;
          return m;
      }
      else
      {
          m=z.next();
          return m;
      }   
  }
  
  public static String bc()
  {
      s=z.next();
      if(z.next().equals(" "))
      {
          s=null;
          return s;
      }
      else
      {
          s=z.next();
          return s;
      }
  
    } 
  }
  </code></pre>