Quiz
CS151 Midterm
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (98)
1What is the output of the following code:
double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);- Ax is 5.5 and y is 5
- Bx is 6 and y is 6
- Cx is 5.5 and y is 5.0
- Dx is 5 and y is 6
- Ex is 6.0 and y is 6.0
2Math.pow(4, 1 / 2) returns ________.
- A1.0
- B0
- C1
- D2
- E2.0
3Suppose a Scanner object is created as follows:
Scanner input = new Scanner(System.in);
What method do you use to read a real number?- Ainput.double();
- Binput.Double();
- Cinput.nextDouble();
- Dinput.nextdouble();
4The following code fragment reads in two numbers:
Scanner input = new Scanner(System.in);
int i = input.nextInt();
double d = input.nextDouble();
What is the incorrect way to enter these two numbers?- AEnter a numeric value with a decimal point, a space, an integer, and then the Enter key.
- BEnter an integer, a space, a double value, and then the Enter key.
- CEnter an integer, an Enter key, a double value, and then the Enter key.
- DEnter an integer, two spaces, a double value, and then the Enter key.
5The expression (int)(76.0252175 ∗ 100) / 100 evaluates to ________.
- A76.03
- B76.02
- C76
- D76.0252175
6According to Java naming convention, which of the following names can be variables?
- ATOTAL_LENGTH
- BfindArea
- CtotalLength
- Dclass
- EFindArea
7Which of the following is a valid identifier?
- Aclass
- B9X
- Cradius
- D$343
- E8+9
8Which of the following are the same as 1545.534?
- A0.1545534e+4
- B1545534.0e-3
- C154553.4e-2
- D1.545534e+3
9What is y displayed?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x + x++;
System.out.println("y is " + y);
}
}- Ay is 1.
- By is 2.
- Cy is 3.
- Dy is 4.
10The ________ method returns a raised to the power of b.
- AMath.power(a, b)
- BMath.pow(b, a)
- CMath.exponent(a, b)
- DMath.pow(a, b)
11Which of the following assignment statements are incorrect?
- Ai = j = k = 1;
- Bi == j == k == 1;
- Ci = 1; j = 1; k = 1;
- Di = 1 = j = 1 = k = 1;
12________ seeks to analyze the data flow and to identify the system's input and output. When you do analysis, it helps to identify what the output is first, and then figure out what input data you need in order to produce the output.
- ARequirements specification
- BTesting
- CAnalysis
- DImplementation
- EDesign
13What is i printed in the following code?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}- A6
- B1
- C0
- D5
14To declare a constant MAX_LENGTH inside a method with value 99.98, you write ________.
- Afinal float MAX_LENGTH = 99.98;
- Bfinal MAX_LENGTH = 99.98;
- Cdouble MAX_LENGTH = 99.98;
- Dfinal double MAX_LENGTH = 99.98;
15-24 % -5 is ________.
- A4
- B-4
- C3
- D0
- E-3
16The expression 4 + 20 / (3 - 1) ∗ 2 is evaluated to ________.
- A24
- B9
- C25
- D4
- E20
17Every letter in a Java keyword is in lowercase.
- AVerdadeiro
- BFalso
18What is the value of (double)(5/2)?
- A2.5
- B3.0
- C2
- D2.0
- E3
19Analyze the following code fragments that assign a boolean value to the variable even.
Code 1:
if (number % 2 == 0)
even = true;
else
even = false;
Code 2:
even = (number % 2 == 0) ? true: false;
Code 3:
even = number % 2 == 0;- AAll three are correct, but Code 1 is preferred.
- BAll three are correct, but Code 3 is preferred.
- CCode 3 has a compile error, because you attempt to assign number to even.
- DCode 2 has a compile error, because you cannot have true and false literals in the conditional expression.
- EAll three are correct, but Code 2 is preferred.
20What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?
- ATrue
- BFalse
- CThere is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.
21Given |x - 2| <= 4, which of the following is true?
- Ax - 2 <= 4 || x - 2 >= -4
- Bx - 2 <= 4 && x - 2 >= 4
- Cx - 2 <= 4 && x - 2 >= -4
- Dx - 2 <= 4 && x - 2 > -4
22Analyze the following program fragment:
int x;
double d = 1.5;
switch (d) {
case 1.0: x = 1;
case 1.5: x = 2;
case 2.0: x = 3;
}- AThe program has a compile error because the required break statement is missing in the switch statement.
- BThe program has a compile error because the required default case is missing in the switch statement.
- CThe switch control variable cannot be double.
- DNo errors.
23Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?
- A9
- B10
- C11
24What is y after the following switch statement is executed?
int x = 3; int y = 4;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}- A1
- B2
- C3
- D4
- E0
25Assume x = 4 and y = 5. Which of the following is true?
- Ax != 5 ^ y != 4
- Bx != 4 ^ y == 5
- C!(x == 4) ^ y != 5
- Dx == 5 ^ y == 4
26Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
- A1 < x < 100 && x < 0
- B((x < 100) && (x > 1)) || (x < 0)
- C((x < 100) && (x > 1)) && (x < 0)
- D(1 > x > 100) || (x < 0)
27Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x-- > 10)?
- A9
- B10
- C11
28The ________ method immediately terminates the program.
- ASystem.halt(0);
- BSystem.terminate(0);
- CSystem.stop(0);
- DSystem.quit(0);
- ESystem.exit(0);
29Which of the following are so called short-circuit operators?
- A|
- B&&
- C||
- D&
30Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("It is even");
}- AThe program runs fine, but displays nothing.
- BThe program has a runtime error.
- CThe program has a compile error.
- DThe program runs fine and displays It is even.
31Analyze the following code:
if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");- AThe statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.
- BThe statement compiles fine, but has a runtime error.
- CThe statement compiles fine.
- DThe statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println(…) statement must be put inside a block.
32What is y displayed in the following code?
- Ay is 0.
- BThe program has a compile error since x is redeclared in the statement int y = x = x + 1.
- Cy is 2 because x + 1 is assigned to x and then x is assigned to y.
- Dy is 1 because x is assigned to y first.
33Given |x - 2| >= 4, which of the following is true?
- Ax - 2 >= 4 && x - 2 < -4
- Bx - 2 >= 4 || x - 2 <= -4
- Cx - 2 >= 4 && x - 2 <= -4
- Dx - 2 >= 4 || x - 2 < -4
34Which of the following is a possible output from invoking Math.random()?
- A0.5
- B1.0
- C3.43
- D0.0
35Analyze the following code:
Code 1:
int number = 45;
boolean even;
if (number % 2 == 0)
even = true;
else
even = false;
Code 2:
int number = 45;
boolean even = (number % 2 == 0);- ACode 2 has compile errors.
- BBoth Code 1 and Code 2 are correct, but Code 2 is better.
- CBoth Code 1 and Code 2 have compile errors.
- DCode 1 has compile errors.
36The order of the precedence (from high to low) of the operators binary +, *, &&, ||, ^ is:
- A*, +, &&, ||, ^
- B*, +, ^, ||, &&
- C*, +, ^, &&, ||
- D^, ||, &&, *, +
- E&&, ||, ^, *, +
37What is the possible output from System.out.println((int)(Math.random() * 4))?
- A0
- B1
- C2
- D3
- E4
38Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x++ > 10)?
- A9
- B10
- C11
39Why do computers use zeros and ones?
- Abecause combinations of zeros and ones can represent any numbers and characters.
- Bbecause binary numbers are simplest.
- Cbecause binary numbers are the bases upon which all other number systems are built.
- Dbecause digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
40If a program compiles fine, but it produces incorrect result, then the program suffers ________.
- Aa runtime error
- Ba logic error
- Ca compilation error
41Computer can execute the code in ________.
- Ahigh-level language
- Bassembly language
- Cnone of the above
- Dmachine language
42Due to security reasons, Java ________ cannot run from a Web browser in the new version of Java.
- Aapplications
- Bservlets
- Capplets
- DMicro Edition programs
43Which of the following lines are not a Java comment?
- A/** comments */
- B/* comments */
- C-- comments
- D** comments **
- E// comments
44One byte has ________ bits.
- A12
- B16
- C4
- D8
45________ is the physical aspect of the computer that can be seen.
- AHardware
- BOperating system
- CSoftware
- DApplication program
46Programming style is important, because ________.
- Aa program may not compile if it has a bad style
- Bgood programming style can make a program run faster
- Cgood programming style helps reduce programming errors
- Dgood programming style makes a program more readable
47________ is the brain of a computer.
- ADisk
- BCPU
- CHardware
- DMemory
48Which JDK command is correct to run a Java application in ByteCode.class?
- Ajava ByteCode
- Bjavac ByteCode.java
- Cjavac ByteCode
- Djava ByteCode.class
- EJAVAC ByteCode
49The main method header is written as ________.
- Apublic static void main(string[] args)
- Bpublic static void main(String[] args)
- Cpublic static main(String[] args)
- Dpublic static void Main(String[] args)
- Epublic void main(String[] args)
50Which of the following are the reserved words?
- Aclass
- Bpublic
- Cstatic
- Dvoid
51The JDK command to compile a class in the file Test.java is ________.
- Ajavac Test.java
- Bjava Test
- CJAVAC Test.java
- Djavac Test
- Ejava Test.java
52Java was developed by ________.
- ASun Microsystems
- BApple
- CCisco Systems
- DMicrosoft
- EIBM
53________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
- AJava JDK
- BJava IDE
- CJava API
- DJava language specification
54Which of the following is not permanent storage devices?
- Afloppy disk
- Bflash stick
- CCD-ROM
- Dmain memory
- Ehard disk
55________ is a program that runs on a computer to manage and control a computer's activities.
- AJava
- BInterpreter
- COperating system
- DModem
- ECompiler
56________ is an operating system.
- AVisual Basic
- BAda
- CWindows
- DJava
- EC++
57The speed of the CPU may be measured in ________.
- Agigahertz
- Bmegabytes
- Cgigabytes
- Dmegahertz
58________ is a software that interprets Java bytecode.
- AJava virtual machine
- BJava API
- CJava compiler
- DJava debugger
59How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++;
}- A0
- B9
- C10
- D8
- E11
60How many times will the following code print "Welcome to Java"?
int count = 0;
while (count++ < 10) {
System.out.println("Welcome to Java");
}- A9
- B0
- C10
- D8
- E11
61What is the output of the following code?
int x = 0;
while (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);- Ax is 1
- Bx is 0
- Cx is 2
- Dx is 3
- Ex is 4
62What will be displayed when the following code is executed?
int number = 6;
while (number > 0) {
number -= 3;
System.out.print(number + " ");
}- A6 3
- B6 3 0
- C3 0
- D3 0 -3
- E0 -3
63Analyze the following fragment:
double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
}- AThe program does not compile because sum and d are declared double, but assigned with integer value 0.
- BAfter the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
- CThe program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
- DThe program never stops because d is always 0.1 inside the loop.
64Will the following program terminate?
int balance = 10;
while (true) {
if (balance < 9)
break;
balance = balance - 9;
}- AYes
- BNo
65Which of the following is true about a while loop?
- AThe body of the loop is executed at least once.
- BThe logical expression controlling the loop is evaluated before the loop is entered and after the loop exists.
- CThe body of the loop may not execute at all.
- DIt is a post-test loop
66What is the output of the following Java code?
int num = 15;
while (num > 0)
num = num - 3;
System.out.println(num);- A0
- B3
- C12
- D15
67int sum = 0;
int limit = console.nextInt();
int counter = 0;
while (counter <= limit)
{
entry = console.nextInt();
sum = sum + entry;
counter++;
}
System.out.println(sum);
The above code is an example of a(n) ____ while loop.- Aflag-controlled
- Bcounter-controlled
- CEOF-controlled
- Dsentinel-controlled
68static final int EndVal = -1;
int double;
int num = console.nextInt();
while (num != EndVal)
{
double = num * 2;
System.out.println(double);
num = console.nextInt();
}
The above code is an example of a(n) ____ while loop.- Aflag-controlled
- Bcounter-controlled
- CEOF-controlled
- Dsentinel-controlled
69A loop is a control structure that causes certain statements to be executed over and over until certain conditions are met.
- AVerdadeiro
- BFalso
70In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.
- AVerdadeiro
- BFalso
71The loop condition of a while loop is reevaluated before every iteration of the loop.
- AVerdadeiro
- BFalso
72A loop that continues to execute endlessly is called an endless loop.
- AVerdadeiro
- BFalso
73In the case of an infinite while loop, the while expression (that is, the loop condition) is always true.
- AVerdadeiro
- BFalso
74If the while expression becomes false in the middle of the while loop body, the loop terminates immediately.
- AVerdadeiro
- BFalso
75The output of the Java code, assuming that all variables are properly declared, is 32.
num = 10;
while (num <= 32)
num = num + 5;
System.out.println(num);- AVerdadeiro
- BFalso
76Control variables are automatically initialized in a loop.
- AVerdadeiro
- BFalso
77A counter-controlled loop is used when the exact number of data entries is known.
- AVerdadeiro
- BFalso
78The output of the Java code, assuming that all variables are properly declared, is: 2 3 4 5 6.
n = 2;
while (n >= 6)
{
System.out.print(n + " ");
n++;
}
System.out.println();- AVerdadeiro
- BFalso
79How many times will the following code print "Welcome to Java"?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);- A8
- B9
- C10
- D11
- E0
80How many times will the following code print "Welcome to Java"?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (++count < 10);- A8
- B9
- C10
- D11
- E0
81Which of the following loops prints "Welcome to Java" 10 times?
A:
for (int count = 1; count <= 10; count++) {
System.out.println("Welcome to Java");
}
B:
for (int count = 0; count < 10; count++) {
System.out.println("Welcome to Java");
}
C:
for (int count = 1; count < 10; count++) {
System.out.println("Welcome to Java");
}
D:
for (int count = 0; count <= 10; count++) {
System.out.println("Welcome to Java");
}- AAC
- BBD
- CAB
- DABC
- EBC
82The following loop displays ________.
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
i++;
}- A1 2 3 4 5
- B1 2 3 4 5 6 7 8 9
- C2 4 6 8 10
- D1 3 5 7 9
- E1 2 3 4 5 6 7 8 9 10
83Do the following two statements in (I) and (II) result in the same value in sum?
(I):
for (int i = 0; i < 10; ++i) {
sum += i;
}
(II):
for (int i = 0; i < 10; i++) {
sum += i;
}- AYes
- BNo
84Is the following loop correct?
for ( ; ; );- AYes
- BNo
85How many times is the println statement executed?
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
System.out.println(i * j);- A100
- B20
- C45
- D10
86What is sum after the following loop terminates?
int sum = 0;
int item = 0;
do {
item++;
sum += item;
if (sum > 4)
break;
}
while (item < 5);- A8
- B6
- C9
- D5
- E7
87What is the output of the following code?
int count;
int num = 2;
for (count = 1; count < 2; count++)
{
num = num + 3;
System.out.print(num + " ");
}
System.out.println();- A5
- B5 8
- C2 5 8
- D5 8 11
88int x = 27;
int y = 10;
do
x = x / 3;
while (x >= y);
How many times does the statement above execute?- Anone
- Bonce
- Ctwice
- Dthree times
89int x = 27;
int y = 10;
do
x = x / 3;
while (x >= y);
If y = 0, how many times would the loop above execute?- A1
- B2
- C3
- D4
90Which of the following does not have an entry condition?
- AEOF-controlled while loop
- Bsentinel-controlled while loop
- Cdo...while loop
- Dfor loop
91A loop is a control structure that causes certain statements to be executed over and over until certain conditions are met.
- AVerdadeiro
- BFalso
92The output of the following Java code is: Stoor.
int count = 5;
System.out.print("Sto");
do
{
System.out.print('o');
count--;
}
while (count >= 5);
System.out.println('r');- AVerdadeiro
- BFalso
93Like a do...while loop, the body of a while loop executes at least once.
- AVerdadeiro
- BFalso
94Because a do...while loop is a post-test loop, the body of the loop may not execute at all.
- AVerdadeiro
- BFalso
95After a break statement executes, the program continues to execute with the first statement after the structure.
- AVerdadeiro
- BFalso
96If a continue statement is placed in a do...while structure, the loop-continue test is evaluated immediately after the continue statement.
- AVerdadeiro
- BFalso
97Loop control variables are automatically initialized in a loop.
- AVerdadeiro
- BFalso
98A counter-controlled loop is used when the exact number of data entries is known.
- AVerdadeiro
- BFalso
Informações
- Descrição
- Computer Science Quiz sobre CS151 Midterm, criado por blank space em 09-10-2023.
- Autor
- blank space
- Idioma
- English
- Visualizações
- 2
- Etiquetas
- Avaliação
- Ainda sem avaliações Avalie este quiz