Welcome Guest | Sign in | Register
Flow Control - Discussion Page For Q.2763 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Flow Control > Questions and Answers

Q: public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}

Which statement is true? 
A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6.
C. There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6.

Answer and Explanation

Answer:There is a syntax error on line 6.

Explanation:
Using the integer 1 in the while statement, or any other looping or conditional construct for that matter, will result in a compiler error. This is old C Program syntax, not valid Java.
A, B and C are incorrect because line 1 is valid (Java is case sensitive so While is a valid class name). Line 8 is also valid because an equation may be placed in a String operation as shown.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.