CS 4A: Chapter 2 – Elementary Programming – Flashcards

Unlock all answers in this set

Unlock answers
question
Are these declarations correct? True/False int length, width; int length; int width;
answer
True
question
Are these declarations legal? True/False int t=4.5; int t=(int)false;
answer
False
question
How would you declare Pi as a constant?
answer
final double PI 3.14159;
question
What is the correct way to assign character 5 to c?
answer
char c = '5';
question
parseInt is a method in what class?
answer
Integer
question
Are these incorrect? True/False i == j == k == 1; i = 1 = j = 1 = k = 1;
answer
True
question
Can you cast a character value to an int, or an int to char? True/False
answer
True
question
What is the Java assignment operator ?
answer
=
question
Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
answer
66
question
Can you change the value of a constant? True/False
answer
False
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;
question
How would you print: smithexam1test.txt?
answer
System.out.println("smithexam1test.txt");
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.
question
If a program compiles fine, but it produces incorrect result, then the program suffers ________.
answer
A logic error
question
________ are valid Java identifiers.
answer
- $Java - _RE4
question
Are these valid identifiers? True/False $343 radius
answer
True
question
The ________ method returns a raised to the power of b.
answer
Math.pow(a, b)
question
You can cast a double value to ________.
answer
- short - byte - int - float - long
question
To assign a double variable d to a float variable x, you write:
answer
x = (float)d;
question
Any assignment statement can be used as an assignment expression. True/False
answer
True
question
A variable may be assigned a value only once in the program. True/False
answer
False
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);
question
Is 'a' larger than 'A'?
answer
Yes
question
The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
answer
76
question
A Java character is stored in ________.
answer
Two bytes
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");
question
-24 % -5 is ________.
answer
-4
question
You can always assign a value of int type to a variable of long type without loss of information. True/False
answer
True
question
Which of the following operators has the highest precedence? /, *, +, Casting
answer
Casting
question
To add number to sum, you write:
answer
- sum += number; - sum = sum + number;
question
Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
answer
A1
question
To assign a double variable d to an int variable x, you write:
answer
x = (int)d;
question
currentTimeMills is a method in the ________ class.
answer
System
question
-15 % 4 is ________.
answer
-3
question
parseDouble is a method in the ________ class.
answer
Double
question
What is the printout of System.out.println('z' - 'a')?
answer
25
question
What is the correct expression of character 4?
answer
'4'
question
Pow is a method is what class?
answer
Math
question
What is the value of (double) 5/2?
answer
2.5
question
The System.currentTimeMills() returns?
answer
The current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
question
Do these expressions yield 0.5? True/False - 1/2.0 - (double) 1/2 - 1.0/2
answer
True
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New