System.out.println("Please enter the amount of money you have here: ");
Scanner have = new Scanner(System.in);
System.out.println("Please enter your starting bet here: ");
Scanner rate = new Scanner(System.in);
int moneyHad = Integer.parseInt(have.next());
int moneyRate = Integer.parseInt(rate.next());
System.out.println(moneyHad + ", " + moneyRate);
有我的代码,这是我的输出。
Please enter the amount of money you have here:
Please enter your starting bet here: 1
1
1, 1
正如你所看到的那样,它会在它询问之前打印它们,这就是为什么输出的第1行没有输入。
请快点帮助我!
答案 0 :(得分:2)
试试这个:
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter the amount of money you have here: ");
int moneyHad = scanner.nextInt();
System.out.print("Please enter your starting bet here: ");
int moneyRate = scanner.nextInt();
System.out.println(moneyHad + ", " + moneyRate);
答案 1 :(得分:1)
您只需要一个扫描程序对象并调用nexInt()
方法来获取后面的条目。