Friday, October 14, 2011

The op= Operators

count += 5 has the same effect as the statement: count = count + 5;

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:
  1. +=
  2. -=
  3. *=
  4. /=
  5. %=
  6. <<=
  7. >>=
  8. >>>=
  9. &=
  10. |=
  11. ^=

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 == "A" "B");

    v++;
    System.out.println(v == "A" "B");
  }
}
 
hasilnya
A
B
 
 
 
 

No comments:

Post a Comment