-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathReverseString.java
More file actions
41 lines (33 loc) · 818 Bytes
/
ReverseString.java
File metadata and controls
41 lines (33 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Write a program, which prompts user for a String,
* and prints the reverse of the String.
*
* The output shall look like:
*
* Enter a String: abcdef
* The reverse of String "abcdef" is "fedcba".
*
*/
package javaexercises.keyboard;
import java.util.Scanner;
/**
*
* @author User
*/
public class ReverseString {
public static void main(String[] args) {
ReverseString aReverseString = new ReverseString();
aReverseString.run();
}
private void run()
{
Scanner in = new Scanner(System.in);
String str;
System.out.print("Enter a String: ");
str = in.next();
for(int i = str.length()-1; i >= 0; i--) {
System.out.print(str.charAt(i));
}
System.out.println();
}
}