title: Reverse a string as per length of first word
body: <p>I am new to Java Strings.
  Actually I have the code to reverse words:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  public class Test2 {
  
      public static void main(String[] args) throws IOException
      {
          System.out.println("enter a sentence");
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          String rev =br.readLine();
  
          String [] bread = rev.split(" ");
          for(int z =bread.length-1;z&gt;=0;z--)
          {
              System.out.println(bread[z]);
          }
  
      }
  }
  </code></pre>
  
  <p>For the above code I get:</p>
  
  <blockquote>
    <p>Input :Bangalore is a city<br>
    Output: City is a Bangalore</p>
  </blockquote>
  
  <p>But I want the output to be like below:</p>
  
  <blockquote>
    <p>Input: Bangalore is a city<br>
    Output:cityaisba ng a lore</p>
  </blockquote>
  
  <p>Another Example:</p>
  
  <blockquote>
    <p>Input:  Hello Iam New To Java.Java is object Oriented language.<br>
    Output: langu age Ori en tedo bjec ti sjava. javaToNe wIamolleH</p>
  </blockquote>
  
  <p>Please help me out</p>