Finals Study Guide (Multiple Choice Section) Flashcards
(83 cards)
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.