Java語言程式設計(基礎篇)第十版 程式設計練習題**3.10(遊戲:加法測驗)
阿新 • • 發佈:2018-12-10
import java.util.Random;
public class AdditionGame {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner input = new java.util.Scanner(System.in);
int number1 = (int)(Math.random() * 100);
int number2 = (int)(Math.random() * 100 );
System.out.println("what is " + number1+ "+" + number2 +"?");
int answer = input.nextInt();
if(number1 + number2 == answer)
{
System.out.println("You are correct!");
}
else {
System.out.println("You are wrong" );
System.out.println(number1 + " + " + number2 + " is " + (number1 +number2));
}
}
}