-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
29 lines (26 loc) · 837 Bytes
/
ReverseString.java
File metadata and controls
29 lines (26 loc) · 837 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
package questions2;
import java.util.Scanner;
public class ReverseString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter tha String");
String name = sc.nextLine();
// Logic 1 use Loop
// String rev = "";
// int len = name.length();
// for(int i= len-1; i>=0; i-- ) {
// rev =rev + name.charAt(i);
// }
// System.out.println("Revers String is : "+ rev);
// Logic 2 use array
// String rev = "";
// char a[] = name.toCharArray();
// int len = a.length;
// for(int i = len-1; i>=0; i--) {
// rev= rev + a[i];
// }
// System.out.println("Revers String is : "+ rev);
StringBuffer sb = new StringBuffer(name);
System.out.println("Revers String is : "+sb.reverse());
}
}