What is the output of the following Java code? ___________________ p
Question 1 (1 point)
What is the output of the following Java code? ___________________
public class Quizzes {
public static void main(String args[]){
String string1 = “CMIS141 “;
String string2 = “is all”;
String string3 = “about Java!”;
String concat = string3.concat(string2).concat(string1);
System.out.println(concat.length());
}
}
Question 1 options:
Save
Question 2 (1 point)
The following Java code contains valid brace placement according to the Google style guide
public class MyClass {
public static void main(String[] args)
{
System.out.println(“Welcome to CMIS 141”);
} // End of main
} // End class
Question 2 options:
| True |
| False |
Save
Question 3 (1 point)
What Java data type is returned while calling the nextGaussian() method in the java.util.Random class?
Question 3 options:
Save
Question 4 (1 point)
Which of the following expression yields an integer between 0 and 100, inclusive?
Question 4 options:
| (int)(Math.random() * 101) |
| int)(Math.random() * 100) |
| (int)(Math.random() * 100) + 1 |
| (int)(Math.random() * 100 + 1) |
Save
Question 5 (1 point)
How many times does the following loop iterate?
public class Quizzes {
public static void main(String args[]){
int cnt = 1;
int maxLoop = 30;
while (cnt < maxLoop) {
cnt++;
}
}
}
Question 5 options:
Save
Question 6 (1 point)
What method would you use in the Scanner class to read an int from standard input in Java?
Question 6 options:
| nextBoolean(); |
| nextFloat(); |
| nextByte(); |
| nextInt(); |
| None of the above |
Save
Question 7 (1 point)
Using the Google style guide document, select the proper declaration of a Java constant.
Question 7 options:
| int CONSTANT SPEED = 3.0;
|
| double final SPEED = 3.0; |
| float FINAL speed = 3.0; |
| Final SPEED = 3.0; |
| None of the above |
Save
Question 8 (1 point)
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));
}
}
Question 8 options:
Save
Question 9 (1 point)
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));
}
}
Question 9 options:
Save
Question 10 (1 point)
What package do you need to import to use the Scanner class in Java?
Question 10 options:
| java.util |
| java.Lang |
| java.io |
| java.nio |
| None of the above |
Save
Question 11 (1 point)
How would you construct an instance of scanner class that will read from the standard input (keyboard) in Java?
Question 11 options:
| Scanner scannerIn = new ScannerIn(); |
| Scanner myOut = new Scanner(); |
| Scanner myOut = new Scanner(Standard.Input); |
| Scanner myOut = new Scanner(Standard.io); |
| None of the above |
Save
Question 12 (1 point)
How many times does the following loop iterate?
public class Quizzes {
public static void main(String args[]){
int cnt = 1;
int maxLoop = 30;
while (cnt < maxLoop) {
if (cnt==3) {
break;
}
cnt++;
}
}
}
Question 12 options:
Save
Question 13 (1 point)
Analyze the following code.
int x = 1;
while (0 < x) && (x < 100)
System.out.println(x++);
Question 13 options:
| The code does not compile because the loop body is not in the braces. |
| The number 1 to 99 are displayed. |
| The number 2 to 100 are displayed. |
| The code does not compile because (0 < x) & (x < 100) is not enclosed in a pair of parentheses. |
| The loop runs for ever. |
Save
Question 14 (1 point)
How many times will the following code print “Welcome to Java”?
int count = 0;
do {
System.out.println(“Welcome to Java”);
count++;
} while (count < 10);
Question 14 options:
| 11 |
| 0 |
| 9 |
| 10 |
| 8 |
Save
Question 15 (1 point)
What is the output of the following Java code? ____________________
public class Quizzes {
public static void main(String args[]){
String string1 = “243”;
String string2 = “true”;
String string3 = “24.1” ;
boolean results = (Boolean.parseBoolean(string2) && false);
System.out.println(results);
}
}
Question 15 options:
Save
Question 16 (1 point)
What is the value of y after executing this Java code?
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
System.out.println(y);
Question 16 options:
| 44 |
| 11 |
| 13 |
| 12 |
| none of the above |
Save
Question 17 (1 point)
According to the Google style guide, Java variable and class names should be named using UpperCamelCase.
Question 17 options:
| True |
| False |
Save
Question 18 (1 point)
Which of the following values would read using the Scanner nextShort() without producing an error?
Question 18 options:
| 32768 |
| -32768 |
| -100000 |
| 100000 |
| None of the above |
Save
Question 19 (1 point)
What is the output of the following Java code: ______________________.
public class Quizzes {
public static void main(String args[]){
double angle = 90;
angle = Math.toRadians(angle);
System.out.println(Math.sin(angle) + Math.pow(Math.cos(angle),2));
}
}
Question 19 options:
Save
Question 20 (1 point)
How many times with the string hi be printed after executing the following code?
public class Quizzes {
public static void main(String args[]){
int colCnt = 0;
int rowCnt = 0;
do {
colCnt = 0;
do {
System.out.print(“hi” + “\t”);
colCnt++;
} while (colCnt < 8);
System.out.print(“\n”);
rowCnt++;
} while (rowCnt < 7);
}
}
Question 20 options:
Save
Question 21 (1 point)
What is the output of the following fragment?
int i = 1;
int j = 1;
while (i < 5) {
i++;
j = j * 2;
}
System.out.println(j);
Question 21 options:
| 16 |
| 4 |
| 64 |
| 8 |
| 32 |
Save
Question 22 (1 point)
What is y after the following for loop statement is executed?
int y = 0;
for (int i = 0; i < 10; i++) {
y += 1;
}
Question 22 options:
| 9 |
| 10 |
| 11 |
| 12 |
| None of the above. |
Save
Question 23 (1 point)
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;
}
Question 23 options:
| –1 |
| 0 |
| 1 |
| 2 |
| None of the above |
Save
Question 24 (1 point)
What is the output of the following code:
int x = 9;
int y = 8;
int z = 7;
if (x > 9) {
if (y > 8){
System.out.println(“x > 9 and y > 8”);
}
else if (z >= 7){
System.out.println(“x <= 9 and z >= 7”);
}
else {
System.out.println(“x <= 9 and z < 7”);
}
}
Question 24 options:
| x > 9 and y > 8 |
| x <= 9 and z >= 7 |
| x <= 9 and z < 7 |
| None of the above |
Save
Question 25 (1 point)
What is the value of the variable cnt after the following code is executed?
public class Quizzes {
public static void main(String args[]){
int cnt = 0;
for (int rowCnt=0; rowCnt <= 4; rowCnt++) {
for (int colCnt=0; colCnt<= 4; colCnt++) {
cnt++;
}
}
}
}
Question 25 options: