-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
27 lines (21 loc) · 836 Bytes
/
ReverseString.java
File metadata and controls
27 lines (21 loc) · 836 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
import java.util.Scanner; // #include <iostream>
// DONE
public class ReverseString {
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in); // object needed for input in java
String x; // input string
String y =" "; // this is needed for assigning a value to y
// INPUT
System.out.print(" Enter a string : "); // basic output syntax
x = obj.nextLine();
// -1 removes unnecessary space which a newbie can't see clearly but
// experienced programmers can see that
for (int i = x.length() - 1; i > -1; i--) // same as c++
{
y += x.charAt(i); // new function sought of charAt(i) for checking
// individual character
}
System.out.print(" Reversed String : " + y); // OUTPUT
}
}