Java Programming 1 Quiz 2 (Chapter 2)
Which operator is used to concatenate two or more strings?
+
What output is produced by these statements? String name = "Joanne Hunt"; ...
11
What is the output of the following code snippet? System.out.printf("%5.3f", 20.0);
20.000
What is the meaning of x = 0; in Java?
It sets the variable x to zero.
Which one of the following statements gives the absolute value of the floating-point number x = -.25.50
Math.abs(x);
Which one of the following statements displays the output as 54321.00?
System.out.printf("%8.2f", 54321.0);
Which of the given System.out.print statements generates the following output? ABCDE"\
System.out.println("ABCDE\"\\");
What happens to the fractional part when a division is performed on two integer variables?
The fractional part is discarded.
What is wrong with the following code snippet? int price; price = 9.42;
The price variable is assigned a decimal value.
Which statement is true?
When declaring a variable, you also specify the type of its values
Which of the following is an assignment statement?
a = 20;
Which is the Java equivalent of the following mathematical expression? c = √(a2 + b2)
c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
Which of the following statements can be used to get the fifth character from a string str?
char c = str.charAt(4);
In an airline reservation system, which data type should be used to store the cost of an airline ticket?
double
Which of the following options declares a float variable?
float age;
The assignment operator ______________________.
places a new value into a variable
How do you compute the length of the string str?
str.length()
How do you extract the first 5 characters from the string str?
str.substring(0, 5)
Which one of the following statements can be used to extract the last five characters from any string ...
str.substring(str.length() - 5, str.length())
The first step in problem solving is ______________________.
to understand the problem and its inputs and outputs