我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P2Q5
*Name:Wang Chaoran
* Description:5 (Addition for three numbers)
The program in Listing 3.3 generates two integers and prompts the
user to enter the addition of these two integers. Revise the program
to generate three single-digit integers and prompt the user to enter
the addition of these three integers.
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;
public class P2Q5
{
public static void main(String[] args)
{
int number1 = (int)(System.currentTimeMillis()%10);
int number2 = (int)(System.currentTimeMillis()*7%10);
int number3 = (int)(System.currentTimeMillis()*9%10);
Scanner scan = new Scanner(System.in);
System.out.print("What is " + number1 + " + " + number2 +" + "+number3+ "?");
int answer = scan.nextInt();
System.out.println(number1 + " + " + number2 + " = " + answer + " is " +
(number1 + number2 +number3 == answer));
}
}
导入论坛查看(31)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing