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?
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?
Nothing will be displayed.
Numbers starting with 0 in Java are numbers in the octal number system and 032767 equals the number 13815 in decimal.
The maximum positive value of type short is 32767 , so the value 32766 is placed in the variable as it is.
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.
iteration don't execute option just means that the body of the loop will not be executed . - Alex ChermeninNothing. 032767 means octal 32767, which is clearly less than 32766, so the program will never work out the body of the cycle.
Source: https://ru.stackoverflow.com/questions/828657/
All Articles