Scanner userIn = new Scanner(System.in);
System.out.println("enter number");
int no = userIn.nextInt();
while (no > 20)
{
System.out.println("too big");
no = userIn.nextInt();
{
if (no <= 20)
{
for (int i=0; i < no; i++)
{
System.out.println(i+1);
}
}
}
}
I am sorry to ask such a silly question, but I am starting to learn programming and I can't put my head around tutorials. I am trying to code where if a given input if larger than 20, it will give the output of "too big" and ask you to enter a number again until it is 20 or less. If the number is 20 or less, it will count from 1 to the chosen number from keyboard. Why does this only work when I enter a number that is large than 20 and after, but not straight away after compiling, is it wrong position, may I ask how I can resolve this? Thank you.