-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings
More file actions
76 lines (45 loc) · 1.53 KB
/
Strings
File metadata and controls
76 lines (45 loc) · 1.53 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package StoreTwo;
import java.util.Scanner;
public class StringExample {
public static void main(String[] args) {
//Example of string concatenation and addition of values in string.
String s = "My Car Brand is Mercedez Benz S class and my lucky number is: ";
System.out.println(s + (2+7) + "\n");
//Example of string concatenation.
String S1, S2;
S1 = "This is the S1 string. ";
S2 = "This is the S2 string. \n";
System.out.println(S1.concat(S2));
//Example for charAt() function.
char ch;
ch = "abc".charAt(2);
System.out.println (ch);
//Example of string replace method.
Scanner myValue = new Scanner(System.in);
System.out.println("Please enter the string value: \n");
String Value1;
Value1 = myValue.nextLine();
String S3 = Value1.replace("Hello", "Hi" + "\n");
System.out.println(S3);
//Example of string trim method.
String S4;
S4 = " This is whitespace sentance. \n";
System.out.println(S4.trim());
//Example second of string trim method.
String Value2;
System.out.println("Please enter the string value2: \n");
Value2 = myValue.nextLine();
System.out.println(Value2.trim());
//Example of string to upper and lower case methods.
String Value3;
System.out.println("Please enter the string value3: \n");
Value3 = myValue.nextLine();
System.out.println(Value3.toLowerCase());
System.out.println(Value3.toUpperCase());
//Example of string to length and capacity case methods.
String Value4;
System.out.println("Please enter the string value4: \n");
Value4 = myValue.nextLine();
System.out.println(Value4.length());
}
}