【发布时间】:2016-04-17 05:41:20
【问题描述】:
所以我最近开始编写一个计算器,它将提供两个 1-50 的随机数和一个 *, + 或 - 符号。但是我不太确定如何实际检查用户输入的答案是否正确,因为我实际上无法计算答案。任何帮助都会非常感谢。
下面的代码(也很抱歉缺少注释)
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello, what is your name?"); //Asks the childs name
Scanner demo = new Scanner(System.in); //creates the scanner
String a = demo.nextLine();
System.out.println("Hi " + a + " I hope your ready for the quiz");
System.out.println("Lets begin");
String [] arr = {"*", "+", "-"};
Random random = new Random();
Random no = new Random();
for(int counter1= 1; counter1 <=1;counter1++){
int select = random.nextInt(arr.length);
int firstnumber;
for(int counter= 1; counter <=1;counter++){
firstnumber = no.nextInt(50);
int firstnumber2;
firstnumber2 = no.nextInt(50);
System.out.println(firstnumber + " " + arr[select] + " " + firstnumber2);
int b = demo.nextInt();
【问题讨论】:
标签: java eclipse string int boolean