+ 1
Is there any mistake here ?
public class Program { static int X=100 static int Y1; public static void main(String[] args) { while (X<=999) Y1=X%10; X=X+1; System.out.println ("Y1="+Y1) } }
7 Answers
+ 12
Errors caused by:
- missing ; after
static int X=100
System.out.println ("Y1="+Y1)
- while loop misses { }
Now only the first statement after while is
executed, that causes an infinite loop.
Your code could be improved by
- naming your variables camelCased, starting in lower case
- defining your variables inside main, because they are only used in that method, you don't need statics here.
+ 9
div is /
mod is %
+ 7
second line: missing semicolon
eighth line: missing semicolon
the while loop should be within curly brackets.
your code will display the numbers 0 to 9 repeatedly (999 times).
+ 1
You are missing ; after static int X = 100
it should be : static int X = 100;
Also semi colon after println statement
System.out.println ("Y1="+Y1);
+ 1
okay thank you for helping me fix the code but how can I use div and mod in java :/ there doesnt seem to be this command in java because when I type it it says error
+ 1
ohh thanks
+ 1
Thanks a lot everything works fine now