请帮忙。我正在尝试创建一个数学学习系统,其中有一个包含4种不同数学运算的菜单。选择操作后,它将生成一组执行该操作的编号。请帮我修复代码
import java.util.Scanner;
import java.util.Random;
public class advanceMath {
public static void main(String[]args) {
Random firstnum = new Random();
int number1 = firstnum.nextInt(9)+1;
Random secondnum = new Random();
int number2 = secondnum.nextInt(9);
Scanner input = new Scanner(System.in);
String dec;
int firstnum,secondnum; int total = 0 ;
System.out.println("choose letter ");
System.out.println("A.Addition");
System.out.println("B.SUBTRACTION");
System.out.println("C.MULTIPLICATION");
System.out.println("D.DIVISION");
System.out.println("letter i choose");
dec = input.next();
if(dec.equalsIgnoreCase("a")){
System.out.println(number1);
firstnum = input.nextInt();
System.out.println(number2);
secondnum = input.nextInt();
total = number1 + number2;
System.out.println("Total = "+ total);
System.out.println("Congratulation"); }
if(dec.equalsIgnoreCase("b")){
System.out.println(number1);
firstnum = input.nextInt();
System.out.println(number2);
secondnum = input.nextInt();
total = number1 - number2;
System.out.println("Total = "+ total);
System.out.println("Congratulation"); }
if(dec.equalsIgnoreCase("c")){
System.out.println(number1);
firstnum = input.nextInt();
System.out.println(number2);
secondnum = input.nextInt();
total = number1 * secondnum;
System.out.println("Total = "+ total);
System.out.println("Congratulation"); }
if(dec.equalsIgnoreCase("d")){
System.out.println(number1);
firstnum = input.nextInt();
System.out.println(number2);
secondnum = input.nextInt();
total = firstnum / secondnum;
System.out.println("Total = "+ total);
System.out.println("Congratulation"); }
else System.exit(0);
}
}
答案 0 :(得分:1)
您使用相同的名称Random firstnum
和int firstnum
与secondnum
相同。更改任何一个的名称
答案 1 :(得分:1)
您已经两次声明pickle
和firstnum
secondnum
并且
Random firstnum = new Random();
Random secondnum = new Random();
删除/重命名其中一个。