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);
}
}
Answer Question 1:
Output:
Explanation:
The above program will generate syntax error because sizeof() operator is not exist in Java.
Answer Question 2:
Output:
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:
Explanation:
The above program will generate syntax error because we cannot use SIZE constant with variables.
Answer Question 4:
Output:
Explanation:
The above program will generate syntax error because unsigned short is not built-in data type in java.
Answer Question 5:
Output:
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