赞
踩
问题及代码:
问题描述:
随机生成三个数,计算并输入这三个数的和,如果输入的正确则输出”You are correct!“,否则输出正确结果
程序代码:
- import java.util.Scanner;
- public class Que {
- public static void main(String[] args){
- int number1=(int)(Math.random()*100);
- int number2=(int)(Math.random()*100);
- int number3=(int)(Math.random()*100);
- System.out.println("What is "+number1+"+"+number2+"+"+number3+"?");
- Scanner input=new Scanner(System.in);
- int answer=input.nextInt();
- if (number1+number2+number3 == answer)
- System.out.println("You are correct !");
- else
- System.out.println("You answer is wrong ! "+number1+number2+number3+" should be "+(number1+number2));
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。