-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlec13.java
More file actions
41 lines (30 loc) · 912 Bytes
/
Copy pathlec13.java
File metadata and controls
41 lines (30 loc) · 912 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
30
31
32
33
34
35
36
37
38
39
40
41
package string;
public class lec13 {
public static void main(String args[]){
StringBuilder sb = new StringBuilder("Tony");
System.out.println(sb);
// char at index 0
System.out.println(sb.charAt(0));
//set character at index
sb.setCharAt(0, 'P');
System.out.println(sb);
//insert
sb.insert(0, 't');
System.out.println(sb);
//delete
sb.delete(0, 1);
System.out.println(sb);
//append
sb.append(" Stark");
System.out.println(sb);
for(int i=0; i<sb.length()/2; i++){
int front = i;
int back = sb.length() - 1 -i;
char frontChar = sb.charAt(front);
char backChar = sb.charAt(back);
sb.setCharAt(front, backChar);
sb.setCharAt(back, frontChar);
}
System.out.println(sb);
}
}