public class Main { public static void main(String[] args) { for (short i = 32766; i<032767; i++){ System.out.println(i); } }} 

What will be displayed in the console and why? Shouldn't 32767 be displayed once?

  • @AlexChermenin and what kind of error it gives: 1) iteration don't execute; 2) compile error; 3) runtime error - Kety Li

2 answers 2

Nothing will be displayed.

  1. Numbers starting with 0 in Java are numbers in the octal number system and 032767 equals the number 13815 in decimal.

  2. The maximum positive value of type short is 32767 , so the value 32766 is placed in the variable as it is.

  3. The number 32766 greater than 13815 (or 032767 in octal numbering), which does not satisfy the condition under which the body of the cycle will be satisfied.

  • and what kind of error it gives: 1) iteration don't execute; 2) compile error; 3) runtime error - Kety Li
  • one
    It does not give any errors. The iteration don't execute option just means that the body of the loop will not be executed . - Alex Chermenin

Nothing. 032767 means octal 32767, which is clearly less than 32766, so the program will never work out the body of the cycle.