-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (46 loc) · 1.91 KB
/
Main.java
File metadata and controls
56 lines (46 loc) · 1.91 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
public class Main {
public static void main(String[] args) {
printInformation("Hello World");
printInformation("");
printInformation("\t \n");
String helloWorld = "Hello World";
System.out.printf("index of r = %d %n", helloWorld.indexOf('r'));
System.out.printf("index of World = %d %n", helloWorld.indexOf("World"));
System.out.printf("index of l = %d %n", helloWorld.indexOf('l'));
System.out.printf("index of l = %d %n", helloWorld.lastIndexOf('l'));
System.out.printf("index of l = %d %n", helloWorld.indexOf('l',3));
System.out.printf("index of l = %d %n", helloWorld.lastIndexOf('l',8));
String helloWorldLower = helloWorld.toLowerCase();
if (helloWorld.equals(helloWorldLower)){
System.out.println("Values match exactly");
}
if (helloWorld.equalsIgnoreCase(helloWorldLower)){
System.out.println("Values match ignoring cases");
}
if (helloWorld.startsWith("Hello")){
System.out.println("String starts with Hello");
}
if (helloWorld.endsWith("World")){
System.out.println("String ends with World");
}
if (helloWorld.contains("World")){
System.out.println("String contains World");
}
if (helloWorld.contentEquals("Hello World")){
System.out.println("Values match exactly");
}
}
public static void printInformation (String string){
int length = string.length();
System.out.printf("Length = %d %n", length);
if (string.isEmpty()){
System.out.println("String is empty");
return;
}
if (string.isBlank()){
System.out.println("String is Blank");
}
System.out.printf("First char = %c %n", string.charAt(0));
System.out.printf("Last char = %c %n", string.charAt(length-1));
}
}