- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathReverseString.java
More file actions
Latest commit
23 lines (18 loc) · 551 Bytes
/
Copy pathReverseString.java
File metadata and controls
23 lines (18 loc) · 551 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* Eden Ghirmai
* ReverseString.java
*
* Reverse a String - Enter a string and the program will reverse it and print it out.*/
publicclassReverseString {
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
System.out.print("What phrase would you like to reverse?: ");
Stringphrase = in.nextLine();
Stringresult = "";
for (inti = phrase.length() - 1; i >= 0; i--) {
Stringletter = phrase.substring(i, i + 1);
result += letter;
}
System.out.println("Reversed Phrase: " + result);
}
}