我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P2Q4
* Name:Wang Chaoran
* Description:Write a program that generates two integers under 100
* and prompts the user to enter the addition of these two integers.
* The program then reports true if the answer is correct, false otherwise.
* The program is similar to Listing 3.3. Include appropriate comments in your
* program.
1 import java.util.Scanner;
2
3 public class AdditionTutor {
4 public static void main(String[] args) {
5 int number1 = (int)(System.currentTimeMillis() % 10);
6 int number2 = (int)(System.currentTimeMillis() * 7 % 10);
7
8 Scanner scan = new Scanner(System.in);
9
10 System.out.print("What is " + number1 + " + " + number2 + "?");
11 int answer = scan.nextInt();
12
13 System.out.println(number1 + " + " + number2 + " = " + answer + " is " +
14 (number1 + number2 == answer));
15 }
16 }
*/
import java.util.Scanner;
class P2Q4
{
public static void main(String[] args)
{
//Generate two random numbers
int number1 = (int)(System.currentTimeMillis()%100);
int number2 = (int)(System.currentTimeMillis()*7%100);
System.out.println("Please input your answer for "+number1+" + "+number2+":");
//Create a Scanner
Scanner scan = new Scanner(System.in);
//Read in addition
int addition = scan.nextInt();
//Calculate and output
if (addition == number1 + number2)
{
System.out.println("The answer is true!");
}
else
{
System.out.println("The answer is false!");
}
}
}
导入论坛查看(32)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing