Java算术运算符示例
以下程序是一个简单的示例,演示了算术运算符。将以下Java程序复制并粘贴到Test.java文件中,然后编译并运行该程序-
示例
public class Test {public static void main(String args[]) {
int a = 10;
int b = 20;
int c = 25;
int d = 25;
System.out.println("a + b = " + (a + b) );
System.out.println("a - b = " + (a - b) );
System.out.println("a * b = " + (a * b) );
System.out.println("b / a = " + (b / a) );
System.out.println("b % a = " + (b % a) );
System.out.println("c % a = " + (c % a) );
System.out.println("a++ = " + (a++) );
System.out.println("b-- = " + (a--) );
//检查d ++和++ d的区别
System.out.println("d++ = " + (d++) );
System.out.println("++d = " + (++d) );
}
}
输出结果
这将产生以下结果-
a + b = 30a - b = -10
a * b = 200
b / a = 2
b % a = 0
c % a = 5
a++ = 10
b-- = 11
d++ = 25
++d = 27
以上是 Java算术运算符示例 的全部内容, 来源链接: utcz.com/z/331028.html