-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.java
More file actions
54 lines (43 loc) · 1.35 KB
/
Copy patharray.java
File metadata and controls
54 lines (43 loc) · 1.35 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
//ARRAY
// public class array {
// public static void main(String[] args){
// char[] name = {'P', 'r', 'i', 's', 'h', 'a'};
// for(char c : name) {
// System.out.print(c);
// }
// System.out.println(" ");
// for (int i = 0, j = name.length - 1; i < j; i++, j--) {
// char temp = name[i];
// name[i] = name[j];
// name[j] = temp;
// }
// for(char c : name) {
// System.out.print(c);
// }
// }
// }
//STRING
// public class array {
// public static void main(String[] args){
// String name = "Prisha";
// System.out.println(name);
// String reversed = "";
// for(int i = name.length() - 1; i >= 0; i--) {
// reversed += name.charAt(i);
// }
// System.out.println(reversed);
// }
// }
//using string builder
// it is not necessary to import the string builder class as it is already included in java.lang
public class array {
public static void main(String[] args){
String name = "Prisha";
System.out.println(name);
StringBuilder reversed = new StringBuilder();
for(int i = name.length() - 1; i >= 0; i--) {
reversed.append(name.charAt(i));
}
System.out.println(reversed.toString());
}
}