Is it a legal statement: for (int i=0, j=1;; i++, j++) : Questions « Statements « SCJP






public class MainClass {
  public static void main(String[] argv) {
    for (int i = 0, j = 1;; i++, j++) {
      System.out.println(i);
      System.out.println(j);
      break;
    }

  }
}
    

A. Legal
B. Illegal








5.16.Questions
5.16.1.What is the output of the following code(nested for loop and continue statement)?
5.16.2.Answer: nested for loop and continue statement
5.16.3.What is the output from the following code(continue statement with label)?
5.16.4.Answer: continue statement with label
5.16.5.Is it a legal loop constructions for while statement?
5.16.6.Answer: while loop
5.16.7.Is it a legal loop constructions for while statement(int)?
5.16.8.Answer: while loop counter
5.16.9.Is it a legal loop constructions(for loop)?
5.16.10.Answer: for loop variable
5.16.11.Is it a legal do-while statement
5.16.12.Answer: do while statement
5.16.13.What would be the output from this code fragment?
5.16.14.Answer: nested if statement
5.16.15.What is the output from the following switch statement?
5.16.16.Answer: using switch statement
5.16.17.What is the output(multi-throw and multi-catch)?
5.16.18.Answer: multi-throw and multi-catch
5.16.19.What is the output(Error and catch statement)?
5.16.20.Answer: Error and catch statement
5.16.21.How to run the following code to enable assertation?
5.16.22.Answer: assert enabling
5.16.23.Change the following code to use enhanced for loop
5.16.24.Answer: enhanced for loop
5.16.25.Is it a legal statement: for (int i=0, j=1; i<10; i++, j++)
5.16.26.Answer: for loop initialization
5.16.27.Is it a legal statement: for (int i=0, j=1;; i++, j++)
5.16.28.Answer: for statement and initialization
5.16.29.Is it a legal statement: for (int i=0, float j=1; ; i++, j++)
5.16.30.Answer: for loop and initialization
5.16.31.Is it a legal statement: for (String s = ""; s.length()<10; s += "A")
5.16.32.Answer: for loop and string loop counter
5.16.33.What is the output(try-catch statement)?
5.16.34.Answer: try-catch statement
5.16.35.Is it a legal statement: while (int a = 0) { /*...*/ }
5.16.36.Answer: while loop count
5.16.37.Which of the following are legal argument types for a switch statement?
5.16.38.Answer: swtich controller variable
5.16.39.What is wrong with the following if statement?
5.16.40.Answer: if statement
5.16.41.What is wrong with the following switch statement?
5.16.42.Answer: switch statement and integer
5.16.43.What is wrong with the following for statement?
5.16.44.Answer: for loop initialization part
5.16.45.What is wrong with the following statement?
5.16.46.Answer: while statement