Skip to content
This repository was archived by the owner on Apr 9, 2019. It is now read-only.

Commit 48fcc8b

Browse files
committed
This Program reverses the users input
1 parent d2e95a0 commit 48fcc8b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

ReverseString.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Scanner;
2+
3+
public class ReverseString {
4+
5+
public static void main(String[] args) {
6+
System.out.print("Please Enter a String to Reverse it: ");
7+
//scan object to read user input
8+
Scanner scan = new Scanner(System.in);
9+
10+
//reading the users input
11+
String input = scan.nextLine();
12+
13+
//changing string into characters
14+
char[] inputCharacters = input.toCharArray();
15+
16+
//getting the length of the string, also the size of the inputCharacter array
17+
int length = input.length();
18+
19+
//looping backward to print the string reverse.
20+
for(int i = length-1; i>=0; i--){
21+
System.out.print(inputCharacters[i]);
22+
}//for
23+
24+
}//main
25+
26+
}//ReverseString

0 commit comments

Comments
 (0)