Advertisement
wadkat

reverse string java

Nov 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication4;
  7. import java.util.Scanner;
  8. /**
  9. *
  10. * @author pclab
  11. */
  12. public class JavaApplication4 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. Scanner kb = new Scanner(System.in);
  19. String word,rev="";
  20. int len, i;
  21. System.out.println("Enter any word ");
  22. word=kb.nextLine();
  23. len=word.length();
  24. for(i=len-1;i>=0;i--)
  25. {
  26. rev=rev+word.charAt(i);
  27. }
  28. System.out.println("The word reversed is "+rev);
  29.  
  30. if (word.equals(rev))
  31. System.out.println("Yes palindrome");
  32. else
  33. System.out.println("No palindrome");
  34. }
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement