
position of sc.nextInt()
Resolved

Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
nan
4 September 2019, 15:33
thanks a lot!
0
Pratika Agnihotri
4 September 2019, 15:29
hey ! the above code will work but the input from user will be taken only once... in order to take more than one input you''ll have to put int i = sc.nextInt(); at two positions - one, before the while loop and the other inside the while loop...
Please feel free to further clarify your doubts
+1
Jeff
27 September 2019, 18:08
adding int i =sc.nextInt(); to the while loop fails to compile, and states that int i is already defined in the main method. Even removing int i = sc.nextInt(); in the main method outside the while loop fails to compile as well (cannot find symbol.)
0
Pratika Agnihotri
2 October 2019, 08:41
Instead of writing int i = sc.nextInt(); inside loop, you write only i=sc.nextInt();
There is no need to declare it inside loop because you have done so once just above while loop.
Hope this helped you !
0
Jeff
10 October 2019, 21:09
What worked for me was defining int i =sc.nextint() inside the while loop, and only inside the while loop. The only lines before the while loop are:
0