JAVA 运算符
算术运算符:

public class HelloWorld{
public static void main(String[] args) {
int age1=24;
int age2=18;
int age3=36;
int age4=27;
int sum=age1+age2+age3+age4;
double avg=sum/4;
int minus=Math.abs(age1-age2);
int newAge=--age1;
System.out.println("四个年龄的总和:"+sum);
System.out.println("四个年龄的平均值:"+avg);
System.out.println("age1 和 age2年龄差值:"+minus);
System.out.println("age1自减后的年龄:"+newAge);
}
}
赋值运算符

public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
three=one+two;
System.out.println("three = one + two ==> "+three);
three+=one;
System.out.println("three += one ==> "+three);
three-=one;
System.out.println("three -= one ==> "+three);
three*=one;
System.out.println("three *= one ==> "+three);
three/=one;
System.out.println("three /= one ==> "+three);
three%=one;
System.out.println("three %= one ==> "+three);
}
}
比较运算符

public class HelloWorld{
public static void main(String[] args) {
int a=16;
double b=9.5;
String str1="hello";
String str2="imooc";
System.out.println("a等于b:" + (a == b));
System.out.println("a大于b:" + (a > b));
System.out.println("a小于等于b:" + (a < b));
System.out.println("str1等于str2:" + (str1.equals(str2)));
}
}
浙公网安备 33010602011771号