Arnab_Manna

string reverse word by word

Sep 10th, 2021
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.*;
  2. class rev_WbW {
  3. String st="";
  4. void input()
  5. {
  6.         Scanner in=new Scanner(System.in);
  7.         System.out.println("enter a sentence :");
  8.         st=in.nextLine();
  9. }
  10. void rev()
  11. {
  12.    String s2="";
  13.    StringTokenizer s1 = new StringTokenizer(st," ");
  14.     while (s1.hasMoreTokens())  
  15.      {    
  16.          /* Prints the elements from the String */  
  17.         s2=s1.nextElement()+" "+s2;    
  18.      }    
  19.         System.out.println(s2);
  20.        
  21. }
  22.         public static void main(String[] args) {
  23.         rev_WbW ob=new rev_WbW();
  24.         ob.input();
  25.         ob.rev();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment