Why won't this simple Java code compile?

I had this question on a software development quiz and am not sure about the rationale behind the answer.

unsigned int x = 1;

while (x> 10) {

System.out.print (x);

     

x ++;

}

My answer: "Compiling the code, but no way out." Correct answer: "The code does not compile".

Has the compiler tried to work as there are no clear syntax errors?

+3


source to share


3 answers


unsigned int x = 1;

This is not valid syntax in Java.



Change it to

int x = 1;

+5


source


in valid unsigned keyword in java, but latest java 8 oracle has an explicit api for long type unsigned



https://blogs.oracle.com/darcy/entry/unsigned_api You can look at the above documentation for more details Hope IT can help u

+5


source


Try running it in an IDE like eclipse. It will show you where the error is.

In this case I am 99% sure that I am unsigned int x = 1;

wrong and should beint x = 1;

+1


source







All Articles