第三章选择
目录
3.2.1if语句:
3.2.2switch语句
3.3.1循环结构的分类:
3.3.2 循环的四要素:
3.3.3for循环
3.3.4while循环
public static void main(String[] args) {
// TODO Auto-generated method stub
//产生两个数
int number1 = (int )(Math.random() * 10);
int number2 = (int )(Math.random() * 10);
//if number1<number2,swap number1 with number2
if(number1<number2) {
int temp =number1;
number1=number2;
number2=temp;
}
//Promptthestudenttoanswer"Whatisnumberl-numbe"
System.out.println("what is "+number1+"-"+number2+"=?");
Scanner scanner = new Scanner(System.in);
int answer =scanner.nextInt();
//Grade the answer and display the result
if(number1-number2==answer) {
System.out.println("you are correct");
}
else {
System.out.println("you are wrong");
System.out.println(number1+"-"+number2+"should be"+(number1-number2));
}
}
3.11计算税率
3.13计算瑞年
3.14**
3.15switch语句
3.16条件表达式
3.18 操作符的优先级和结合原则
上一篇: mysql lvs keepalived 双主热备
下一篇: 第三章 最简单的程序设计--顺序结构