+ 1

Error User Input

Hi guys. Could you help me please to solve my code problem? I got an error when I try to create multiple input function in java code. I don't understand how to solve it because the first paragraph "Welcome Weebs :v" works well. I getting stuck in here .. so please help me :"v. Btw sorry for my bad English :) The code 🔽🔽🔽 https://code.sololearn.com/c2kIrvJCdZr3/?ref=app Thanks before :). Peace

28th Jun 2019, 11:02 AM
Darell Christopher Mona
Darell Christopher Mona - avatar
4 Answers
+ 6
Here's how to make it work: -Remove line 7 (delete moneyInput variable) or comment it with //; -Rename ageInput to input (line 6) -Lines 8 and 9 change ageInput and moneyInput to input. Like this: Scanner input = new Scanner(System.in); // Scanner moneyInput = new Scanner(System.in); int age = input.nextInt(); int money = input.nextInt(); And it should work. When you enter your numbers you should use enter. For example: 18 Hit enter⤵️ 100
28th Jun 2019, 11:36 AM
voja
voja - avatar
+ 2
use one scanner for this Scanner Input = new Scanner(System.in); //Scanner moneyInput = new Scanner(System.in); int age = Input.nextInt(); int money = Input.nextInt(); ... // if (age <= 18 ) is redundant, this branch is always < 18, no need to test it else { System.out.println("Sorry kid.. you are still young. try another movie :D"); } /* // this else never execute, because age is >=18 or <18, no third way else { System.out.println("You are not a human -_-"); } */
28th Jun 2019, 4:39 PM
zemiak
+ 2
Thank you guys for your suggestions. I have rewrote the code and now the code is working properly :)
29th Jun 2019, 12:05 AM
Darell Christopher Mona
Darell Christopher Mona - avatar