0
Help me in my code.Tell the error!
I want to make a program such that it prints value of i till the user input and increments it. https://code.sololearn.com/cHWTKE7u5tg9/?ref=app
7 Respostas
+ 1
Below the Scanner add
int num = j.nextInt();
And in your for loop replace j.nextInt() with num
+ 1
Thank you ~ swim ~
For the help
0
JavaBobbo thank you its working but by the way can you please explain that why does assigning the value to other integer makes the code work whereas both hold the same value.
Thank you
0
This is how it works.
When you enter a number for example 5 your variable num got the value 5 now, and so fast we press enter we will go through the loop and go from 0 to 5.
Your loop: for(int i=0;i<=num;i++)
int i = 0; we start count from 0
i <= num; so long as 0 is less OR equals then 5
i++; add 1
So first loop, we go throught it and checks if 0 is less or equals to 5
if not? then we add 1, second round lets check if 1 is less or equals 5? no its not, so the loop keeps loop until we hit 5