Examveda
Examveda

What is the output for the below code?
public class Test{
      public static void main(String[] args){
            int i = 010;
            int j = 07;
            System.out.println(i);
            System.out.println(j);
      }
}

A. 8 7

B. 10 7

C. Compilation fails with an error at line 3

D. Compilation fails with an error at line 5

E. None of these

Answer: Option A

Solution(By Examveda Team)

By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8


This Question Belongs to Java Program >> Data Types And Variables

Join The Discussion

Comments ( 4 )

  1. Brijesh Kumar
    Brijesh Kumar :
    4 years ago

    Priyank sharma: output will be 8

  2. Rajesh C
    Rajesh C :
    5 years ago

    010 means
    10 = 001 000
    Right to left (001 000)
    2³= 8

  3. Yubraj Singh
    Yubraj Singh :
    6 years ago

    in code written plrintln which means 7 must be print in next line it print in same line

  4. Priyank Sharma
    Priyank Sharma :
    7 years ago

    What is the O/P of following program:

    public class DemoOctal {
    public static void main(String[] args) {
    int i=010;

    System.out.println(i);
    }
    }

Related Questions on Data Types and Variables