Deck 2: Basic Elements of Java
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 2: Basic Elements of Java
1
The null string contains only the blank character.
False
2
The symbol '5' does not belong to the char data type because 5 is a digit.
False
3
Suppose x = 18.6. The output of the statement System.out.println((int)(x) / 3); is 6.
True
4
Suppose that index is an int variable. The statement index = index + 1; is equivalent to index++;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The == characters are a special symbol in Java.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
A value such as 'd' is called a character constant.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The pair of characters // is used for single line comments.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Suppose console is a Scanner object initialized with the standard input device. The expression console.nextInt(); is used to read one int value and the expression console.nextDouble(); is used to read two int values.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
An operator that has only one operand is called a unique operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Suppose console is a Scanner object initialized with the standard input device and feet and inches are int variables. Consider the following statements: feet = console.nextInt(); inches = console.nextInt(); These statements require the value of feet and inches to be input on separate lines.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
When a value of one data type is automatically changed to another data type, an implicit type coercion has occurred.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
When evaluating a mixed expression, all integer operands are converted to floating-point numbers with the decimal part of zero.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
Java automatically initializes all variables.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
The number of significant digits in a double variable is up to 15.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a is 3.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The Java language is strongly typed.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The data type float is a floating-point data type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
An identifier can be any sequence of characters and integers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Operators of the same precedence are evaluated from right to left.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
The value of a variable may change during program execution.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Operators that have two operands are called ____.
A) unary operators
C) operators
B) binary operators
D) expressions
A) unary operators
C) operators
B) binary operators
D) expressions
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following statements about a named constant is NOT true?
A) Its content cannot change during program execution.
B) Its value can be changed during program execution.
C) It is a memory location.
D) It is declared using the reserved word final.
A) Its content cannot change during program execution.
B) Its value can be changed during program execution.
C) It is a memory location.
D) It is declared using the reserved word final.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
The length of the string "first java program" is:
A) 16
C) 19
B) 18
D) 20
A) 16
C) 19
B) 18
D) 20
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is a valid int value?
A) 3279
C) 3270.00
B) 3,279
D) -922337203684547758808
A) 3279
C) 3270.00
B) 3,279
D) -922337203684547758808
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Suppose x = 8. After the execution of the statement y = x++; y is 8 and x is 10.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
In Java, a period is used to terminate a statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.
A) semantic
C) syntax
B) logical
D) grammatical
A) semantic
C) syntax
B) logical
D) grammatical
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
If ++x is used in an expression, first the expression is evaluated, and then the value of x is incremented by 1.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
The value of the expression 14 % 3 is ____.
A) 1
C) 3
B) 2
D) 4
A) 1
C) 3
B) 2
D) 4
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
The character sequence \n moves the insertion point at the end of the current line.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Both System.out.println and System.out.print can be used to output a string on the standard output device.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
The value of the expression 5 + 10 % 4 - 3 is ____.
A) 0
C) 4
B) 2
D) 5
A) 0
C) 4
B) 2
D) 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is a valid char value?
A) '$_'
C) 'n\'
B) '%'
D) "a"
A) '$_'
C) 'n\'
B) '%'
D) "a"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
The expression (double)(5 + 4) evaluates to ____.
A) 8
C) 9.0
B) 9
D) 10.0
A) 8
C) 9.0
B) 9
D) 10.0
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
What type of Java statement(s) stores a value in a variable?
A) input
B) output
C) assignment
D) Both an input statement and an assignment statement
A) input
B) output
C) assignment
D) Both an input statement and an assignment statement
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is a valid Java identifier?
A) $pay
C) newGrade!
B) 4myGrade!
D) 1dollar
A) $pay
C) newGrade!
B) 4myGrade!
D) 1dollar
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose that x and y are int variables and x = 7 and y = 8. After the statement: x = x * y - 2; executes, the value of x is ____.
A) 42
C) 56
B) 54
D) 58
A) 42
C) 56
B) 54
D) 58
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
The memory allocated for a double value is ____ bytes.
A) 2
C) 8
B) 4
D) 16
A) 2
C) 8
B) 4
D) 16
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following is NOT a reserved word in Java?
A) double
C) static
B) throws
D) num
A) double
C) static
B) throws
D) num
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
The expression (int)8.7 evaluates to ____.
A) 8
C) 9.0
B) 8.0
D) 9
A) 8
C) 9.0
B) 8.0
D) 9
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
____ are executable statements that inform the user what to do.
A) Variables
C) Named constants
B) Prompt lines
D) Expressions
A) Variables
C) Named constants
B) Prompt lines
D) Expressions
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the following program. // Insertion Point 1 public class CircleArea {// Insertion Point 2 static final float PI = 3.14 public static void main(String[]args) {//Insertion Point 3 float r = 2.0; float area; area = PI * r * r; System.out.println("Area = " + area);} // Insertion Point 4} In the above code, where do the import statements belong?
A) Insertion Point 1
C) Insertion Point 3
B) Insertion Point 2
D) Insertion Point 4
A) Insertion Point 1
C) Insertion Point 3
B) Insertion Point 2
D) Insertion Point 4
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following is the newline character?
A) \r
C) \l
B) \n
D) \b
A) \r
C) \l
B) \n
D) \b
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Given char ch; int num; double pay; Which of the following assignment statements are valid? (i) ch = '*'; (ii) pay = num * pay; (iii) rate * 40 = pay;
A) Only (i) is valid
C) (ii) and (iii) are valid
B) (i) and (ii) are valid
D) (i) and (iii) are valid
A) Only (i) is valid
C) (ii) and (iii) are valid
B) (i) and (ii) are valid
D) (i) and (iii) are valid
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The declaration int a, b, c; is equivalent to which of the following?
A) int a , b c;
C) int abc;
B) int a;
D) int a b c;
A) int a , b c;
C) int abc;
B) int a;
D) int a b c;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Suppose x = 4 and y = 2. If the statement x *= y; is executed once, what is the value of x?
A) 2
C) 8
B) 4
D) This is an illegal statement in Java.
A) 2
C) 8
B) 4
D) This is an illegal statement in Java.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
What is the output of the following statement? System.out.println("Welcome \n Home");
A) WelcomeHome
B) Welcome Home
C) Welcome
D) Welcome \n Home
A) WelcomeHome
B) Welcome Home
C) Welcome
D) Welcome \n Home
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
The standard output object in Java is ____.
A) output
C) Sys.out
B) System.out
D) System.in
A) output
C) Sys.out
B) System.out
D) System.in
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____.
A) beta = beta - 1;
C) beta = beta - 1;
B) beta = beta - 1;
D) alpha = beta;
A) beta = beta - 1;
C) beta = beta - 1;
B) beta = beta - 1;
D) alpha = beta;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Consider the following program. public class CircleArea {static Scanner console = new Scanner(System.in); static final float PI = 3.14; public static void main(String[]args) {float r; float area; r = console.nextDouble(); area = PI * r * r; System.out.println("Area = " + area);}} To successfully compile this program, which of the following import statement is required?
A) import java.io;
C) import java.lang;
B) import java.util;
D) No import statement is required
A) import java.io;
C) import java.lang;
B) import java.util;
D) No import statement is required
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck