+ 1

What is wrong with my code? I got 'cannot find the variable on this line' int x= myScanner.nextInt();

The error to this line of code is at the .nextInt I am trying to create a program that allows the user to input to integers and generate the sum of the numbers.

16th Jan 2021, 2:02 PM
Cindy_ywairimu
Cindy_ywairimu - avatar
7 Antworten
+ 1
Send the link of your code . So that it will be easier to figure it
16th Jan 2021, 2:06 PM
Atul [Inactive]
+ 1
I have already shared yhe code publicly. I hope you can find it on my profile. I'd appreciate your help.
16th Jan 2021, 2:15 PM
Cindy_ywairimu
Cindy_ywairimu - avatar
+ 1
Then why can't it run when I input the user inputs?
16th Jan 2021, 2:20 PM
Cindy_ywairimu
Cindy_ywairimu - avatar
+ 1
Here's what happens, if I'm adding up numbers like 2 and 3, and I input them in the same line like 2 3 it will output 5 but if I input the numbers in different lines one on top and the other on the adjacent line, it will display an error.
16th Jan 2021, 7:57 PM
Cindy_ywairimu
Cindy_ywairimu - avatar
+ 1
No problem it happened with me also when I was making my first calculator
17th Jan 2021, 4:56 AM
Atul [Inactive]
0
No errors are present in your code
16th Jan 2021, 2:19 PM
Atul [Inactive]
0
you have to place the 2 inputs in 2 lines, for example to get 5+7 you have to put the 5 in the first line, and 7 in the 2nd line of user input. Example: http://prntscr.com/wuroym
16th Jan 2021, 2:45 PM
Aleksandar Aleksovski
Aleksandar Aleksovski - avatar