提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在Java中使用算术运算符
public class ArithmeticDemo { /** from nowjava.com - 时代Java**/ public static void main(String[] args) { int result = 1 + 2; // result is now 3 System.out.println("1 + 2 = " + result); int original_result = result; result = result - 1; // result is now 2 System.out.println(original_result + " - 1 = " + result); original_result = result; /* from n o w j a v a . c o m - 时代Java */ result = result * 2; // result is now 4 System.out.println(original_result + " * 2 = " + result); original_result = result; result = result / 2; // result is now 2 System.out.println(original_result + " / 2 = " + result); original_result = result; result = result + 8; // result is now 10 System.out.println(original_result + " + 8 = " + result); original_result = result; result = result % 7; // result is now 3 System.out.println(original_result + " % 7 = " + result); } }