public class MainClass {
public static void main(String[] arg) {
int count = 1;
count += 5;
System.out.println(count);
count = count + 5;
System.out.println(count);
}
}
6 11
The complete set of op= operators:
- +=
- -=
- *=
- /=
- %=
- <<=
- >>=
- >>>=
- &=
- |=
- ^=
The ternary operator (The Conditional Operator): result = value>conditionValue ? result1 : result2
if(value > conditionValue){
result = result1;
}else{
result = result2;
}
logical_expression ? expression1 : expression2
public class MainClass {
public static void main(String[] args) {
int v = 1;
System.out.println(v == 1 ? "A" : "B");
v++;
System.out.println(v == 1 ? "A" : "B");
}
}
hasilnya
A B
No comments:
Post a Comment