/**
* 游戏:学习加法。
* 产生两个100以内的整数。
* 提示用户输入这两个整数的和:
* 如果答案正确,程序报告true;否则,报告false。
*/
package Test;
import java.util.Scanner;
public class T34Scanner {
public static void main(String[] args) {
int number1 = (int)(Math.random() * 100);
int number2 = (int)(Math.random() * 100);
System.out.println("number1 is: " + number1 + " and number2 is: " + number2);
Scanner input = new Scanner(System.in);
System.out.print("Enter the sum of number1 + number2: ");
int sum = input.nextInt();
System.out.println((sum == (number1 + number2))
? "true" : "The sum is " + (number1 + number2));
// boolean even = (sum == (number1 + number2));
// System.out.println(even);
// if (even == false)
// System.out.println("The sum is " + (number1 + number2));
}
}
第3章:游戏:学习加法
最新推荐文章于 2024-08-06 16:23:45 发布