Q:

Java find output programs (Data Types) | set 1

belongs to collection: Java find output programs

0

Find the output of Java programs | Data Types | Set 1: Enhance the knowledge of Java Data Types concepts by solving and finding the output of some Java programs.

Question 1:

public class MainClass {
  public static void main(String[] args) {
    int Len = 0;
    int A = 100;

    Len = sizeof(int);
    System.out.println("Len : " + Len);

    Len = sizeof(A);
    System.out.println("Len : " + Len);
  }
}

Question 2:

public class MainClass {
  public static void main(String[] args) {
    System.out.println(Long.SIZE);
    System.out.println(Double.SIZE);
    System.out.println(Integer.SIZE);
  }
}

Question 3:

public class MainClass {
  public static void main(String[] args) {
    Long A = 234;
    Double PI = 3.14;

    System.out.println(A.SIZE);
    System.out.println(PI.SIZE);
  }
}

Question 4:

public class Main {
  public static void main(String[] args) {
    unsigned short A = 234;
    int B = 254;
    int C = 0;

    C = A * 10 + B - A;

    System.out.println(C);
  }
}

Question 5:

public class Main {
  public static void main(String[] args) {
    short A = 234;
    int B = 254;
    int C = 0;

    C = A * 10 + B - A;

    System.out.printf("C : %d", C);
  }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Question 1:

Output:

MainClass.java:6: error: '.class' expected
    Len = sizeof(int);
                    ^
1 error

Explanation:

The above program will generate syntax error because sizeof() operator is not exist in Java.

Answer Question 2:

Output:

64
64
32

Explanation:

In the above program, we created a class MainClass that contains a main() method, which is the entry point for the program. Here, we used SIZE constant of Long, Double, and Integer class. The SIZE constant contains the size of specified class in bits. The size of Long is 64 it means 8 bytes.

Here, we used the println() method to print the values on the console screen.

Answer Question 3:

Output:

MainClass.java:3: error: incompatible types: int cannot be converted to Long
    Long A = 234;
             ^
1 error

Explanation:

The above program will generate syntax error because we cannot use SIZE constant with variables.

Answer Question 4:

Output:

Main.java:3: error: not a statement
    unsigned short A = 234;
    ^
Main.java:3: error: ';' expected
    unsigned short A = 234;
            ^
2 errors

Explanation:

The above program will generate syntax error because unsigned short is not built-in data type in java.

Answer Question 5:

Output:

C : 2360

Explanation:

In the above program, we created a class Main that contains a main() method, which is the entry point for the program. In the main() method, we created three local variables A, B, and C initialized with 234, 254, and 0 respectively.

Now evaluate the expression:

C = A*10+B-A;
C = 234*10+254-234;
C = 2340+254-234;
C = 2360

Here, we used printf() method to print the value of C in formatted manner.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java find output programs (Data Types) | set 2... >>