Java Programming Quiz 2 – Flashcards

Unlock all answers in this set

Unlock answers
question
________ is the Java assignment operator.
answer
=
question
Which statement imports the Scanner class?
answer
import java.util.Scanner;
question
Every letter in a Java keyword is in lowercase.
answer
True
question
A variable must be declared before it can be assigned a value.
answer
True
question
Which of the following are correct names for variables according to Java naming conventions? (Choose two.)
answer
radius findArea
question
To improve readability and maintainability, you should declare ________ instead of using literal values such as 3.14159.
answer
constants
question
Which of the following are correct ways to declare variables? (Choose two.)
answer
int length; int width; int length, width;
question
Which of the following expressions will yield 0.5? (Choose three.)
answer
1.0 / 2 1 / 2.0 (double) 1 / 2
question
Java keywords can be used as identifiers.
answer
False
question
Which of the following is a constant, according to Java naming conventions? (Choose two.)
answer
MAX_VALUE
question
Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read an int value?
answer
input.nextInt();
question
Which of these data types requires the most amount of memory?
answer
long
question
If you enter 1 2 3, when you run this program, what will be the output? import java.util.Scanner; public class Test1 { public static void main(String[ ] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); } }
answer
2.0
question
Which of the following is a valid identifier? (Choose two.)
answer
$343 radius
question
To declare an int variable number with initial value 2, you write
answer
int number = 2;
question
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
answer
final double MAX_LENGTH = 99.98;
question
To assign a value 1 to variable x, you write
answer
x = 1;
question
Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read a double value?
answer
input.nextDouble();
question
Analyze the following code: public class Test { public static void main(String[] args) { int i = k + 2; System.out.println(i); } }
answer
The code has an error because variable k has not been declared.
question
What is the result of 45 / 4?
answer
11
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New