第1关:算数运算符
package step1;
import java.util.Scanner;
public class Cal {
public static void main(String[] args) {
/*********start*********/
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个整数");
int a = sc.nextInt();
System.out.println("请输入第二个整数");
int b = sc.nextInt();
System.out.println("两数相加的结果为:"+(a+b));
System.out.println("两数相减的结果为:"+(a-b));
System.out.println("两数相乘的结果为:"+a*b);
System.out.println("两数相除的结果为:"+a/b);
System.out.println("两数取余数的结果为:"+a%b);
/*********end*********/
}
}
第2关:关系运算符
package step2;
import java.util.Scanner;
public class Relative {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
/*********start*********/
System.out.println("a==b="+(a==b));
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));
/*********end*********/
}
}
第3关:逻辑运算符
package step3;
import java.util.Scanner;
public class testLogic {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
boolean a=sc.nextBoolean();
boolean b=sc.nextBoolean();
boolean c=sc.nextBoolean();
/*********start *********/
System.out.println(!a);
System.out.println(a&&b);
System.out.println(c||b);
System.out.println(a);
/*********end *********/
}
}
第4关:三元运算符
package step4;
import java.util.Scanner;
public class TestYear {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int year=sc.nextInt();
boolean result;
/********start********/
result=(year%4==0&&year%100!=0) ? true : false ;
System.out.println(year + "年是否为闰年:" + result);
/********end********/
}
}
第5关:运算符的优先级
package step5;
import java.util.Scanner;
public class TestDemo5 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("输入:");
int m=sc.nextInt();
int n=sc.nextInt();
System.out.println("输出:");
/*****start*****/
System.out.println( 2*(m+n) );
System.out.println( (m-n)%3 );
System.out.println((m-n)/2 + (m+n)*2);
/*****end*****/
}
}
第6关:选择自测题
BACCAA