Review Flashcards
(21 cards)
The format specifier ________ is a placeholder for an int value.
%d
What would be displayed as a result of executing the following code?
final int x = 22, y = 4;
y += x;
System.out.println(“x = “ + x + “, y = “ + y)
Error because named constants with final
What is the value of z after the following code is executed?
int x = 5, y = 28;
float z;
z = (float) (y / x);
5.0
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
1
int x, y = 15;
x = y–;
15
Scanner keyboard = new Scanner(System.in);
System.out.print(“Enter a number: “);
int number = keyboard.nextInt();
while (number < 100 || number > 500)
{
System.out.print(“Enter another number: “);
number = keyboard.nextInt();
}
range 100-500
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
18.0
int x = 11;
do
{
x += 20;
} while (x <= 100);
5
int temp = 200;
if (temp > 90) {
System.out.println(“This porridge is too hot.”);
}
if (temp < 70) {
System.out.println(“This porridge is too cold.”);
}
if (temp == 80) {
System.out.println(“This porridge is just right!”);}
The porridge is too hot
The empty statement is denoted by what symbol?
semicolon
a counter-controlled iteration is also known as
definite iteration
System.out.printf(“%s”, “I love “, “Java”);
i love
In a class containing methods with the same name, the methods are distinguished by ________.
Number of arguments
Types of arguments
Return type
(a) and (b)
(b) and (c)
a and b
math methods
min(), max(), avg(), sin(), cos(), tan(), round(), ceil(), floor(), abs() etc.
Which of the following methods is not in the Math class?
ceil
abs
parseInt
Log
parseInt
Overloaded methods always have the same _________.
method name
return type
number of parameters
order of the parameters
method name
Which of the following promotions of primitive types is not allowed to occur?
char to int.
double to float.
int to double.
short to long.
double to float
Stacks
Lifo
Any field declared with keyword ________ is constant.
static
const
constant
Final
final
Which is a correct static method call of Math class method sqrt?
sqrt(900);
math.sqrt(900);
Math.sqrt(900);
Math math = new Math(); math.sqrt(900);
Math.sqrt(900);
Which expression is equivalent to if (!(grade == sentinelValue))?
if (grade !== sentinelValue)
if (grade != sentinelValue)
! if (grade == sentinelValue)
! if (grade !== sentinelValue)
B if (grade != sentineValue)