初学Java if选择语句
2021-07-01 02:06
标签:public out == you port number main cti correct 初学Java if选择语句 标签:public out == you port number main cti correct 原文地址:https://www.cnblogs.com/leo2li/p/9639385.html 1 import java.util.Scanner;
2
3 public class SubtractionQuiz {
4 public static void main(String[] agrs) {
5 int number1 = (int)(Math.random() * 100);
6 int number2 = (int)(Math.random() * 100);
7
8 if (number1 number2) {
9 int temp = number1;
10 number1 = number2;
11 number2 = temp;
12 }
13
14 System.out.print("What is " + number1 + " - " + number2 + "?");
15 Scanner input = new Scanner(System.in);
16 int answer = input.nextInt();
17
18 if (number1 - number2 == answer)
19 System.out.println("You are correct!");
20 else
21 System.out.println("You are wrong\n" + number1 + " - " + number2 + " should be " + (number1 - number2));
22
23 }
24 }