Fundamentals (Tony Gaddis) Questions
and Answers Latest Version Already
Passed
What is the default value of a `double` variable in Java?
✔✔ 0.0
How do you convert a number to its absolute value in Java?
✔✔ Using `Math.abs(number);`
What is the result of `System.out.println(10 > 5 && 3 < 4);`?
✔✔ true
How do you check if a string is empty in Java?
✔✔ `string.isEmpty();`
What happens if you divide a floating-point number by zero in Java?
✔✔ It results in infinity or NaN (Not a Number).
1
,How do you generate a random number between 0 and 1 in Java?
✔✔ `Math.random();`
How do you convert a string to lowercase in Java?
✔✔ `string.toLowerCase();`
What is the purpose of the `Scanner` class in Java?
✔✔ It is used to read input from the user.
What is the result of `System.out.println(4 * 3);`?
✔✔ 12
How do you declare a character variable in Java?
✔✔ `char letter = 'A';`
What is the result of `System.out.println(5 + 5.0);`?
✔✔ 10.0
2
,How do you check if a number is positive in Java?
✔✔ `number > 0`
What is the purpose of the `toString()` method in Java?
✔✔ It converts an object to a string representation.
How do you round a number down to the nearest integer in Java?
✔✔ `Math.floor(value);`
What is the result of `System.out.println(5 == 5);`?
✔✔ true
What is the purpose of the `Math.pow()` method in Java?
✔✔ It raises a number to the power of another number.
What is the result of `System.out.println(3 * 2 + 1);`?
✔✔ 7
3
, What is the output of `System.out.println("Hello " + "World!");`?
✔✔ "Hello World!"
How do you define a floating-point variable in Java?
✔✔ `float pi = 3.14f;`
What is the default value of an integer variable in Java?
✔✔ 0
How do you declare a variable to store the age of a person in Java?
✔✔ `int age;`
How do you create a constant value in Java?
✔✔ Using the `final` keyword.
What happens when you try to divide an integer by zero in Java?
✔✔ It results in an ArithmeticException.
4