Question 118Asked in DSSSB TGT Computer Science, 25 Jun 2023, Shift 1 (8:30 AM)

What is the output of the following java program? public class Solution{

What is the output of the following java program? public class Solution{ public static void main(String[] args){ int[] p = {121, 201, 017}; for(int j = 0; j < p.length; j++){ System.out.print(p[j] + " "); } } }
  1. A1121 201 17
  2. B1121 201 15
  3. CCompilation error
  4. DRuntime error
Show answerHide answer

Correct answer: (B) 1121 201 15

Explanation

A leading 0 makes 017 an octal literal, which equals 15. The program prints 121 201 15, which is option (B) (its text shows a stray leading 1).

From DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 1 (8:30 AM)

This is question 118 of DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 1 (8:30 AM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.