運算子(operators)
public class operators_operands { public static void main(String[] args) { int a=5, b=2; // 同類型變數可連續宣告 int sum1, sum2; > System.out.println(a/b); // 商,取整數部分 System.out.println(a%b); // 取餘數 sum1 = ++a; // ++前置(prefix), a先+1,再將a值指派給sum1 sum2 = b++; // ++後置(postfix), b值先指派給sum2,b再+1 System.out.println(sum1); System.out.println(sum2); } }
前置運算子(prefixPostfix)
public class PrefixPostfix { public static void main(String[] args) { int x=3; System.out.println("Before Prefix X = "+ ++x); System.out.println("After Prefix X = "+ x); x=3; System.out.println("Before Postfix X = "+ x++); System.out.println("After Postfix X = "+ x); } }