Advertisement
ZhenghaoZhu

ForLoopsString

Jan 23rd, 2016
53
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.  
  3. public class ForLoopString{
  4.   public static void main (String []args){
  5.     Scanner input = new Scanner(System.in);
  6.     System.out.println("Input a word:");
  7.     String word = input.nextLine();
  8.     String reverseword = " ";
  9.     char lastletter = word.charAt(word.length() - 1);
  10.     for(int i = word.length()-1; i >= 0; i--){
  11.       reverseword=reverseword + word.charAt(i);}
  12.     System.out.println(word.charAt(0));
  13.     System.out.println(lastletter);
  14.     System.out.println(reverseword);
  15.     System.out.println(word);
  16.  
  17.    
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement