-
Notifications
You must be signed in to change notification settings - Fork 0
/
ternaryOperator.java
45 lines (32 loc) · 1.12 KB
/
ternaryOperator.java
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
package com.journaldev.util;
public class TernaryOperator {
public static void main(String[] args) {
System.out.println(getMinValue(4,10));
System.out.println(getAbsoluteValue(-10));
System.out.println(invertBoolean(true));
String str = "Australia";
String data = str.contains("A") ? "Str contains 'A'" : "Str doesn't contains 'A'";
System.out.println(data);
int i = 10;
switch (i){
case 5:
System.out.println("i=5");
break;
case 10:
System.out.println("i=10");
break;
default:
System.out.println("i is not equal to 5 or 10");
}
System.out.println((i==5) ? "i=5":((i==10) ? "i=10":"i is not equal to 5 or 10"));
}
private static boolean invertBoolean(boolean b) {
return b ? false:true;
}
private static int getAbsoluteValue(int i) {
return i<0 ? -i:i;
}
private static int getMinValue(int i, int j) {
return (i<j) ? i : j;
}
}