CS 4A: Chapter 2 – Elementary Programming – Flashcards
41 test answers
Unlock all answers in this set
Unlock answers 41question
parseInt is a method in what class?
answer
Integer
Unlock the answer
question
Are these incorrect? True/False i == j == k == 1; i = 1 = j = 1 = k = 1;
answer
True
Unlock the answer
question
Can you cast a character value to an int, or an int to char? True/False
answer
True
Unlock the answer
question
What is the Java assignment operator ?
answer
=
Unlock the answer
question
Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
answer
66
Unlock the answer
question
Can you change the value of a constant? True/False
answer
False
Unlock the answer
question
What do you write to declare a constant MAX_LENGTH inside a method with value 99.98?
answer
final double MAX_LENGTH = 99.98;
Unlock the answer
question
How would you print: smithexam1test.txt?
answer
System.out.println("smithexam1test.txt");
Unlock the answer
question
The following code fragment reads in two numbers: Scanner scanner = new Scanner(System.in); int i = scanner.nextInt(); double d = scanner.nextDouble(); What are the correct ways to enter these two numbers?
answer
- Enter an integer, a space, a double value, and then the Enter key. - Enter an integer, an Enter key, a double value, and then the Enter key. - Enter an integer, two spaces, a double value, and then the Enter key.
Unlock the answer
question
If a program compiles fine, but it produces incorrect result, then the program suffers ________.
answer
A logic error
Unlock the answer
question
________ are valid Java identifiers.
answer
- $Java - _RE4
Unlock the answer
question
Are these valid identifiers? True/False $343 radius
answer
True
Unlock the answer
question
The ________ method returns a raised to the power of b.
answer
Math.pow(a, b)
Unlock the answer
question
You can cast a double value to ________.
answer
- short - byte - int - float - long
Unlock the answer
question
To assign a double variable d to a float variable x, you write:
answer
x = (float)d;
Unlock the answer
question
Any assignment statement can be used as an assignment expression. True/False
answer
True
Unlock the answer
question
A variable may be assigned a value only once in the program. True/False
answer
False
Unlock the answer
question
Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?
answer
System.out.println((char)i);
Unlock the answer
question
Is 'a' larger than 'A'?
answer
Yes
Unlock the answer
question
The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
answer
76
Unlock the answer
question
A Java character is stored in ________.
answer
Two bytes
Unlock the answer
question
The ________ method displays an input dialog for reading a string.
answer
- String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); - String string = JOptionPane.showInputDialog(null, "Enter a string"); - String string = JOptionPane.showInputDialog("Enter a string");
Unlock the answer
question
-24 % -5 is ________.
answer
-4
Unlock the answer
question
You can always assign a value of int type to a variable of long type without loss of information. True/False
answer
True
Unlock the answer
question
Which of the following operators has the highest precedence? /, *, +, Casting
answer
Casting
Unlock the answer
question
To add number to sum, you write:
answer
- sum += number; - sum = sum + number;
Unlock the answer
question
Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
answer
A1
Unlock the answer
question
To assign a double variable d to an int variable x, you write:
answer
x = (int)d;
Unlock the answer
question
currentTimeMills is a method in the ________ class.
answer
System
Unlock the answer
question
-15 % 4 is ________.
answer
-3
Unlock the answer
question
parseDouble is a method in the ________ class.
answer
Double
Unlock the answer
question
What is the printout of System.out.println('z' - 'a')?
answer
25
Unlock the answer
question
What is the correct expression of character 4?
answer
'4'
Unlock the answer
question
Pow is a method is what class?
answer
Math
Unlock the answer
question
What is the value of (double) 5/2?
answer
2.5
Unlock the answer
question
The System.currentTimeMills() returns?
answer
The current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
Unlock the answer
question
Do these expressions yield 0.5? True/False - 1/2.0 - (double) 1/2 - 1.0/2
answer
True
Unlock the answer