Which of the following is used to declare an integer in Java?
A
num B
int C
integer D
number
Analysis & Theory
`int` is the correct keyword for declaring integers in Java.
Which numeric data type is used for large whole numbers in Java?
A
int B
byte C
short D
long
Analysis & Theory
`long` can store much larger integers than `int`.
Which of the following stores decimal values with high precision?
A
int B
double C
char D
boolean
Analysis & Theory
`double` is a 64-bit floating point number with more precision than `float`.
What is the output of:
`int x = 5; System.out.println(x / 2);`
A
2.5 B
2 C
3 D
2.0
Analysis & Theory
Integer division in Java truncates the decimal, so `5 / 2` results in `2`.
Which operator is used to find the remainder in Java?
A
/ B
% C
// D
\
Analysis & Theory
`%` is the modulo operator and gives the remainder.
What is the output of:
`System.out.println(5.0 / 2);`
A
2 B
2.0 C
2.5 D
3
Analysis & Theory
When one operand is a double, Java performs floating-point division.
Which of these numeric types has the smallest range?
A
int B
byte C
double D
float
Analysis & Theory
`byte` is an 8-bit integer with a range from -128 to 127.
What is the result of:
`int a = 10; a += 5;`
A
5 B
10 C
15 D
0
Analysis & Theory
`a += 5` is equivalent to `a = a + 5`, so `a` becomes `15`.
Which data type is best for currency or precise decimal values?
A
float B
int C
double D
BigDecimal
Analysis & Theory
`BigDecimal` is used when high precision is needed (e.g., financial apps).
What will happen with this code?
`int x = 2147483647 + 1;`
A
It gives an error B
It becomes 2147483648 C
It overflows and wraps to -2147483648 D
It prints nothing
Analysis & Theory
`int` has a max value of 2147483647; adding 1 causes overflow.