Finals Study Guide (Multiple Choice Section) Flashcards
Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.)
System.out.println(“Welcome to Java”);
System.out.print(“Welcome to Java”);
________ is the brain of a computer.
CPU
Every letter in a Java keyword is in lowercase.
false
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
final double MAX_LENGTH = 99.98;
________ is the physical aspect of the computer that can be seen.
Hardware
________is interpreted.
Java
Which of the following assignment statements is incorrect? (Choose all that apply.)
i = 1 = j = 1 = k = 1;
i = 1; j = 1; k = 1;
i == j == k == 1;
A block is enclosed inside ________.
braces
The main method header is written as:
public static void main(String[ ] args)
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); } }
2.0
________ is the Java assignment operator.
=
________ are instructions to the computer. (Choose two.)
Programs
Software
Which of the following are correct ways to declare variables? (Choose two.)
int length, width;
int length; int width;
Which of the following is a valid identifier? (Choose all that apply.)
class
$343
radius
Suppose you define a Java class as follows:
public class Test {
}
In order to compile this program, the source code should be stored in a file named
Test.java
One byte has ________ bits.
8
To assign a value 1 to variable x, you write
x = 1;
Every statement in Java ends with ________.
a semicolon (;)
Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply.)
radius
findArea
Suppose a Scanner object is created as follows:
Scanner input = new Scanner(System.in);
What method do you use to read an int value?
input.nextInt();
What is 1 + 1 + 1 + 1 + 1 == 5?
true
What is the printout of the following switch statement? char ch = 'a'; switch (ch) { case 'a': case 'A': System.out.print(ch); break; case 'b': case 'B': System.out.print(ch); break; case 'c': case 'C': System.out.print(ch); break; case 'd': case 'D': System.out.print(ch); }
a
What is the printout of the following switch statement?
char ch = ‘b’;
switch (ch) { case 'a': System.out.print(ch); case 'b': System.out.print(ch); case 'c': System.out.print(ch); case 'd': System.out.print(ch); }
bbb
Analyze the following code:
if (x < 100) && (x > 10)
System.out.println(“x is between 10 and 100”);
The statement has compile errors because (x 10) must be enclosed inside parentheses.
The equal comparison operator in Java is ________.
==
Suppose income is 4001, what is the output of the following code:
if (income > 3000) { System.out.println("Income is greater than 3000"); } else if (income > 4000) { System.out.println("Income is greater than 4000");
}
Income is greater than 3000
Analyze the following code.
boolean even = false;
if (even) {
System.out.println(“It is even!”);
}
The code displays nothing.
Which of the following code displays the area of a circle if the radius is strictly positive?
if (radius > 0) System.out.println(radius * radius * 3.14159);
Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
((x < 100) && (x > 1)) || (x < 0)
In Java, the word true is ________.
a Boolean literal
The following code displays ________.
double temperature = 50;
if (temperature >= 100) System.out.println("too hot"); else if (temperature );
just right
Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?
if (x > 0) if (y > 0) System.out.println("x > 0 and y > 0"); else if (z > 0) System.out.println("x 0");
x 0;
Which of the Boolean expressions below is incorrect? (Choose three.)
(x != 0) || (x = 0)
(true) && (3 => 4)
(-10 < x < 0)