I put the insttruction: int i = sc.nextInt(); before the block while, the programme took too long time to run. However, when I put this instruction inside the block while, it works. Can someone explain to me why please?
position of sc.nextInt()
You must be signed in to leave a comment
4 September 2019, 15:33
thanks a lot!
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
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.)
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 !
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: