+ 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) } }

4th Mar 2017, 10:59 AM
Agamemnon Kyriazis
Agamemnon Kyriazis - avatar
7 odpowiedzi
+ 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.
4th Mar 2017, 11:08 AM
Tashi N
Tashi N - avatar
+ 9
div is / mod is %
4th Mar 2017, 11:43 AM
Tashi N
Tashi N - avatar
+ 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).
4th Mar 2017, 11:10 AM
Mario L.
Mario L. - avatar
+ 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);
4th Mar 2017, 11:09 AM
Giriraj Bhagat
Giriraj Bhagat - avatar
+ 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
4th Mar 2017, 11:41 AM
Agamemnon Kyriazis
Agamemnon Kyriazis - avatar
+ 1
ohh thanks
4th Mar 2017, 11:46 AM
Agamemnon Kyriazis
Agamemnon Kyriazis - avatar
+ 1
Thanks a lot everything works fine now
4th Mar 2017, 12:12 PM
Agamemnon Kyriazis
Agamemnon Kyriazis - avatar