University of Maryland. CMIS 141 Quiz 2, version 1. Questions With Answers. 100% Answered.1. Using the Google style guide document, select the proper decla
... [Show More] ration of a Java constant.
a. int CONSTANT SPEED = 3.0;
b. double final SPEED = 3.0;
c. float FINAL speed = 3.0;
d. Final SPEED = 3.0;
e. None of the above
2. What is the output of the following Java code: ______________________.
public class Quizzes {
public static void main(String args[]){
int momAge = 62;
int dadAge = 64;
System.out.println(Math.max(momAge, dadAge) + Math.min(momAge, dadAge));
}
}
126
3. What method would you use in the Scanner class to read an int from standard input in Java?
a. nextBoolean();
b. nextFloat();
c. nextByte();
d. nextInt();
e. None of the above
4. What is the value of balance after the following code is executed?
int balance = 10;
while (balance >= 1) {
if (balance < 9) {
break;
}
balance = balance - 9;
}
a. –1
b. 0
c. 1
d. 2
e. None of the above
5. How would you construct an instance of scanner class that will read from the standard input
(keyboard) in Java?
a. Scanner scannerIn = new ScannerIn();
b. Scanner myOut = new Scanner();
c. Scanner myOut = new Scanner(Standard.Input);
d. Scanner myOut = new Scanner(Standard.io);
e. None of the above
6. What is the output of the following Java code: ____________________.
public class Quizzes {
public static void main(String args[]){
double examAvg = 85.9983;
System.out.println(Math.ceil(examAvg));
}
}
86.0
7. Analyze the following code:
public class Test {
public static void main (String args[]) {
int i = 0;
for (i = 0; i < 10; i++);
System.out.println(i + 4);
}
}
a. The program has a compile error because of the semicolon (;) on the for loop line.
b. The program compiles despite the semicolon (;) on the for loop line, and displays 4.
c. The program compiles despite the semicolon (;) on the for loop line, and displays 14.
d. The program has a runtime error because of the semicolon (;) on the for loop line.
8. In the following Java code, what is the largest possible value that could be printed while executing
the following code?
// Import
import java.util.Random;
public class Quizzes {
public static void main(String args[]){
// create random object
Random randomNo = new Random();
for (int i=0; i<10000; i++) {
System.out.println(randomNo.nextInt(100));
}
}
}
99
9. Which of the following values would read using the Scanner nextShort() without producing an error?
a. 32768
b. -32768
c. -100000
d. 100000
e. None of the above
10. What Java data type is returned while calling the nextGaussian() method in the java.util.Random
class?
double [Show Less]