Programming I Quiz 1-4
Which of the following is a valid Java identifier? 5dollar / $pay / newGrade! / 4myGrade!
$pay
Which of the following is a valid char value? '%' 'n\' '$_' "a"
'%'
The length of the string "first java program" is:
18
The value of the expression 14 % 3 is _______
2
Which of the following is a valid int value? 3279 / -922337203684547758808 / 3270.00 / 3,279
3279
The value of the expression 5 + 10 % 4 - 3 is _____
4
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 ____.
54
Suppose x = 20. The output of the statement System.out.println(x / 3); is:
6
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. (T or F)
False
Java automatically initializes all variables. (T or F)
False
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. (T or F)
False
The symbol '5' does not belong to the char data type because 5 is a digit. (T or F)
False
In Java, a period is used to terminate a statement. (T or F)
False (;)
The character sequence \n moves the insertion point at the end of the current line. (T or F)
False (\n = new line!)
Suppose console is a Scanner object initialized with the standard input device and initial is a char variable. To store the first letter of user's input, we could use initial = console.next( ).charAt(0); (T or F)
True
Suppose x = 8. After the execution of the statement y = x++; y is 8 and x is 9. (T or F)
True
The == characters are a special symbol in Java. (T of F)
True
The data type float is a floating-point data type. (T or F)
True
The number of significant digits in a double variable is up to 15. (T or F)
True
The pair of characters // is used for single line comments. (T or F)
True
The value of a variable may change during program execution. (T or F)
True
When evaluating a mixed expression, integer operands are converted to floating-point numbers with the decimal part of zero. (T or F)
True
Suppose a, b, and c are int variables and a = 3 and b = 6. What the values is assigned to each variable after the following statement executes? c = 2 * (--a) + (b++);
a=2, b=7, c=10
Suppose <console> is a Scanner object initialized with the standard input device and <major> is a String variable. Which Java statement is most appropriate to read user's major from keyboard and store it in the variable <major>? a) major = console.next( ); b) major = console.nextDouble( ); c) major = console.nextLine( ); d) major = console.nextInt( );
c (VERIFY)
Which of the following outputs 56734.9875 to three decimal places? a) System.out.printf(".3f%", 56734.9875); b) System.out.printf(".03f%", 56734.9875); c) System.out.printf("%.3f", 56734.9875); d) System.out.printf("3f%", 56734.9875);
c (VERIFY)
The declaration <int a, b, c;> is equivalent to which of the following? a) int abc; b) int a , b c; c) int a b c; d) int a; int b; int c;
d
What is the output of the following statement? <System.out.println("Welcome \n Home");> a) WelcomeHome b) Welcome \n Home c) Welcome Home d) Welcome Home
d
Which of the following statements about a named constant is NOT true? a) It is a memory location b) It is declared using the reserved word final c) Its content can't change during program execution d) Its value can be changed during program execution
d
Suppose console is a Scanner object initialized with the standard input device and price is a double variable. Which of the following statements can be used to read price: i) price = console.nextInt( ); ii) price = console.nextDouble( ); iii) price = console.next( );
ii
What is the package needed to import Scanner code?
java.util
Given float a; long b; Assume all variables have been initialized to zero. Which of the following assignment statements are valid? i) a = 7.2; ii) b = a; i ii both neither
neither
Which of the following is NOT a reserved word in Java? static / void / num / double
num
Given int c; double d; Assume all variables have been initialized to zero. Which of the following assignment statements are valid? i) c = 36.7/5 + (int)15; ii) d = (long)8.3; i ii both neither
only ii
____ are executable statements that inform the user what to do.
prompt lines
The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.
syntax
Suppose the String variable str points to the String object "Sunny day" at the memory address 3600. Then the value of str is:
the memory address, 3600