Latest Update Graded A+
Which of these is not a primitive data type in Java?
A. `int`
B. `double`
C. `char`
✔✔D. `String`
How do you store a decimal value in a variable in Java?
✔✔A. `double x = 10.5;`
B. `decimal x = 10.5;`
C. `int x = 10.5;`
D. `float x = 10;`
What will be the output of `System.out.println("Hello" + " World!");`?
A. HelloWorld!
✔✔B. Hello World!
C. Hello + World!
1
,D. Compilation error
How do you create a character variable in Java?
A. `char letter = "A";`
✔✔B. `char letter = 'A';`
C. `char letter = "A";`
D. `Character letter = 'A';`
How do you concatenate two strings in Java?
A. `str1.merge(str2);`
✔✔B. `str1 + str2;`
C. `str1.concat(str2);`
D. Both B and C
What is the result of the following code: `System.out.println(20 - 5 * 2);`?
A. 30
✔✔B. 10
C. 5
2
,D. 0
Which of the following is the correct syntax for creating a for loop in Java?
A. `for(int i = 0; i < 10; i++)`
✔✔B. `for(int i = 0; i < 10; i++) { }`
C. `for(int i = 0 i < 10 i++) { }`
D. `for(int i = 0; i < 10; i++)`
What is the purpose of the `Math.pow()` method in Java?
A. To calculate the factorial of a number
✔✔B. To calculate the power of a number
C. To calculate the square root of a number
D. To find the absolute value of a number
What will the following code print: `System.out.println();`?
A. 3
✔✔B. 3
C. 3.0
3
, D. Compilation error
What is the default value of an integer variable in Java?
A. 0
✔✔B. 0
C. null
D. 1
Which of the following is a valid way to declare a float variable in Java?
A. `float f = 10.5;`
✔✔B. `float f = 10.5f;`
C. `float f = 10.5d;`
D. `float f = 10;`
What will be the output of `System.out.println("Java" + 10 + 20);`?
A. 30
✔✔B. Java1020
C. Java30
4