Ayushi Ayushi - 3 months ago 14
Java Question

Why is my code not running? Java

I am new to coding. I was just trying some new code. There are no errors according to the compiler but the code just won't run. I tried it on 2 different environment TextPad and BlueJ and have the same problem in both.

Here is my code and see if you can correct:

/** This program displays my name 10 times on 10 different lines!*/
public class Name10{
public static void main(String[] args)
{
int count = 1;
while(count <11);
{ System.out.println("John");
count = count + 1;
}
}
}


Please help! Thank you for your time!

Thank you all for your help! The problem was indeed with the semicolon on the while loop!

Answer

You are using '=' instead of '+' when you want to update counter.

change to:

count = count + 1;

or

count++;

another mistake is that you are using ';' after the while.

change to:

while(count <11)
 { 
     System.out.println("John");
     count++;
 }
Comments