title: program reversing a sentence in java using character array
body: <p>I have to reverse a sentence but the problem is i'm not getting the exact output.
  If input is "today is monday" my output is "y a d n o m   s   m o n d a y" 
  but I have to get  "y a d n o m  s i  y a d o t"
  Please help me out...</p>
  
  <pre><code>public class reversesentence {
      public static void main(String[] args) {
          String sent = "today is monday";
          char ch[] = sent.toCharArray();
          int n= ch.length;
  
  //        System.out.println("before reverse:");
  //        for(int i=0;i&lt;n;i++){
  //            System.out.print(ch[i]+" ");    
  //        }
  
          for(int i=0; i&lt;n; i++){
              //System.out.println("hello");
               ch[i]= ch[n-i-1];
  
          }
  
          System.out.println("\nafter reverse:");
          for(int i=0;i&lt;n;i++){
              System.out.print(ch[i]+" ");    
          }
      }
  
  }
  </code></pre>