Test 1 Flashcards
(19 cards)
Which of the following code displays the area of a circle if the radius is positive?
if (radius > 0) System.out.println(radius * radius * 3.14159);
Suppose income is 4001, what is the output of the following code?
if (income > 3000) {
System.out.println(“Income is greater than 3000”);}
else if (income > 4000) {
System.out.println(“Income is greater than 4000”);}
Income is greater than 3000
Analyze the following code.
int x = 0;
if (x > 0); {
System.out.println(“x”);
}
The symbol x is always printed.
The following code displays ___________.
double temperature = 50;
if (temperature >= 100) System.out.println(“too hot”);
else if (temperature <= 40) System.out.println(“too cold”);
else System.out.println(“just right”);
just right
The extension name of a Java source code file is:
java
Suppose you write the code to display “Cannot get a driver’s license” if age is less than 16 and “Can get a driver’s license” if age is greater than or equal to 16. Which of the following code is the best?
if (age < 16) System.out.println(“Cannot get a driver’s license”);
else System.out.println(“Can get a driver’s license”);
What is the printout of the following code fragment?
double x = 5.5;
int y = (int)x;
System.out.println(“x is “ + x + “ and y is “ + y) ;
x is 5.5 and y is 5
Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?
if (x > 0)
if (y > 0)
System.out.println(“x > 0 and y > 0”);
else if (z > 0)
System.out.println(“x < 0 and z > 0”);
x < 0 and z > 0
Which of the following assignment statements is illegal?
int t = 4.5;
If a program compiles fine, but it produces incorrect result, then the program suffers __________.
logical error
The expression “Java “ + 1 + 2 + 3 evaluates to ________.
Java 123
What is the value of (double) (5/2)?
2.0
What is the printout of the following code?
double x = 10.1;
int y = (int)x;
System.out.println(“x is “ + x + “ and y is “ + y);
x is 10.1 and y is 10
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<100) && (x > 10) must be enclosed inside parentheses.
Suppose s is a string with the value “program”, char x = s.charAt(4) will return __________.
‘r’
To assign a double variable d to an int variable x, you write
x = (int)d;
What is the exact output of the following code?
double area = 3.5;
System.out.print(“area”);
System.out.print(area);
area3.5
Analyze the following code.
boolean even = false;
if (even) { System.out.println(“It is even!”);}
The code displays nothing.
What method do you use to read an int value?
input.nextInt();