package cn.itjcs.jichu;
public class OperatorDemo {
public static void main(String[] args) {
//算术运算符: + - * / %
int a = 10;
int b = 3;
System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b); //两个整数做除法,结果一定是整数,因为最高类型是整数.
System.out.println(a * 1.0 / b); //再除不尽时,要取到小数部分,在前部分乘以1.0
System.out.println(a % b);
System.out.println("------------------------------");
//拆分三位数 取出个位,十位,百位
int data = 996;
int ge = data % 10;
System.out.println(ge);
int shi = data / 10 % 10;
System.out.println(shi);
int bai = data / 100;
System.out.println(bai);
}
}
java基本算术运行符 + - * / %
最新推荐文章于 2024-08-23 16:53:34 发布