forked from foojayio/getting_started_with_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfThenElse.java
More file actions
33 lines (28 loc) · 1.15 KB
/
Copy pathIfThenElse.java
File metadata and controls
33 lines (28 loc) · 1.15 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
public class IfThenElse {
public static void main (String[] args) {
// Compare integer value
int testValue = 1;
// We don't change the variable in this example,
// but here could be some code to define this variable.
if (testValue <= 1) {
System.out.println("The value is 1 or smaller");
} else if (testValue == 2) {
System.out.println("The value is 2");
} else {
System.out.println("The value is " + testValue);
}
// Compare strings
String string1 = "Hello world";
String string2 = "Hello" + " " + "world";
String string3 = "Hello World";
System.out.println("Are string1 and string2 equal? "
+ string1.equals(string2));
System.out.println("Are string1 and string3 equal? "
+ string1.equals(string3));
System.out.println("Are string1 and string3 equal ignoring the case? "
+ string1.equalsIgnoreCase(string3));
if (string1.equalsIgnoreCase(string3)) {
System.out.println("string1 and string3 are equal ignoring the case");
}
}
}