1.Operational character
2.Arithmetic operator
public class AeithmeticOperator{
public static void main(String[] args) {
System.out.println(10 / 4);//2
System.out.println(10.0 / 4);//2.5
double d = 10 / 4;//2.0
System.out.println(d);
//%的本质 a % b = a - a / b * b
System.out.println(10 % 3);//1
System.out.println(-10 % 3);//-1
System.out.println(10 % -3);//1
System.out.println(-10 % -3);//-1
//++
int i = 10;
i++;
++i;
System.out.println("i=" + i);//12
/*
作为表达式使用
前++:++i 先自增后赋值
后++:i++先赋值后自增
*/
int j = 8;
int k = ++j;//先自增后赋值
int k = j++;//先赋值后自增
System.out.println("k=" + k + "j=" + j );//9 9 8 9
}
}
3.Arithmetic operator exrecise
public class ArithmeticOperatorExercise{
public static void main(String[] args) {
//first question
int b = 1;
b = b++;//(1)temp = b;(2)b = b + 1;(3)b = temp;
System.out.println(b);//1
//Sceond question
int a = 1;
a = ++a;//(1)a = a + 1;(2)temp = a;(3)a = temp;
System.out.println(a);//2
//Third questiomn
int i1 = 10;
int i2 = 20;
int i = i1++;
System.out.print("i=" + i);//10
System.out.println("i2=" + i2);//20
i = --i2;
System.out.print("i=" + i);//19
System.out.println("i2=" + i2);//19
//Fourth question
int allday = 59;
int week = allday / 7;
int day = allday % 7;
System.out.println("合" + week + "个星期零" + day + "天" );
//Fifth question
double fahrenheit = 234.6;
double centigrade = 5.0 / 9 * (fahrenheit - 100);
System.out.println("华氏温度" + fahrenheit + "=摄氏温度" + centigrade);
}
}
4.Relational operator(Comparison operator)
5.Logical operator
The knowledge learning in the article comes from
【零基础 快速学Java】韩顺平 零基础30天学会Java_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1fh411y7R8?p=32