
java computer science test
Created on 6th January 2025
Grade level: Grade 10th grade
1 plays
10 Questions
No Description
Questions (10)
1. What is the correct way to declare a variable in Java?
int x = 10;
4 choice options
2. What will be the output of the following code: 'System.out.println(Math.abs(-5));'
5
4 choice options
3. Which of the following statements correctly uses an if-else statement?
if (x > 10) { System.out.println('x is greater than 10'); }
4 choice options
4. What is the output of the following code: 'int a = 5; int b = 10; System.out.println(a + b);'
15
4 choice options
5. Which of the following is a correct way to use the Math.sqrt() function?
Math.sqrt(16);
4 choice options
6. How do you initialize a variable with a floating-point number in Java?
float myNumber = 5.75;
4 choice options
7. What will be the result of the following code: 'int x = 8; if (x % 2 == 0) { System.out.println('Even'); } else { System.out.println('Odd'); }'
Even
4 choice options
8. What does the following code snippet do? 'double result = Math.pow(2, 3);'
Calculates 2 raised to the power of 3, result is 8.
4 choice options
9. What will the following code output: 'int x = 5; x += 3; System.out.println(x);'
8
4 choice options
10. Which of the following will NOT compile in Java?
int number = 10.5;
4 choice options