Advertisement
advictoriam

Untitled

Jan 11th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    Reads a string, reverses the order the characters within the
  5.    string, and prints out the result.
  6.    Input: the value of s, a string
  7.    Output: the string reversed
  8. */
  9. public class ReverseString
  10. {
  11.    public static void main(String[] args)
  12.    {
  13.       Scanner in = new Scanner(System.in);
  14.       String s = in.nextLine();
  15.  
  16.       String reversed = "";
  17.  
  18.       for(int i = s.length() - 1; i > -1; i--)
  19.       {
  20.          reversed += s.charAt(i);
  21.       }
  22.       System.out.println(reversed);
  23.    }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement