CMSC FINAL UPDATED ACTUAL Questions and CORRECT Answers
1. Which of the following lines of code correctly writes System.out.println("Hel-
"Hello" to the screen. lo");
2. Fill in the blanks of the code below : main( Public, static, void, String[]
args){
3. The class name does not have to be the same as the False
file name
4. The command to compile a Java program is: Java
Hello.java.
5. Explain the steps that need to happen to take code 1. Code is written
from it being written to it running and producing out- 2. Code is compiled
put. 3. The byte code is read
6. What does the virtual machine do? Choose all answers 1. runs the class file
that apply. 2. runs the byte code
7. Logic errors are the hardest errors to find. T/F True
8. While running a program, it unexpectedly stops. What 1. runtime
type of error is that? Choose all answers that apply. 2. logic
9. Write the algorithm for the following computer prob- Set ASSESS_PERCENT =
lem: 0.22
Bear Corporation needs a program to calculate their Enter month1Sales,
quarterly assessment fee. They will total the sales for month2Sales,
the past quarter (a three month period) and the pay Month3Sales
22% of the total sales as their quarterly assessment Calculate totalSales by
fee. adding month1Sales,
month2Sales,
Month3Sales
, Calculate assessmentFee
by totalSales * AS-
SESS_PERCENT
Output assessmentFee
10. What is a variable? Choose all parts below that are 1. can change
relevant. 2. memory location
3. named
11. Name two primitive Java data types that represent int, byte, short, long
whole numbers.
12. Name two primitive Java data types that represent float, double
floating point numbers.
13. For each error shown below match it to the correct out- 1. Compile-time error
put: a compile-time error, run-time error, or no error. 2. run-time error
3. compile-time error
1. System.out.Println("Greetings, Planet Earth!"); 4. compile-time error
2. System.out.println(); 5. compile-time error
3. float scale = 7854.345368564323; 6. no error
4. System.out.println("I love VCU!")
5. Double x = 43.454;
6. System.out.print(45 % 342);
14. What is displayed in the following code segment? 1. 5
int numerator = 34; 2. 4
int denominator = 6;
1. System.out.println(numerator / denominator);
2..out.println(numerator % denominator);
15. Comment
, A part of a program that contains information about
the program but has no effect when the program runs
is called a .
16. Given the following declaration statement, write a count++
statement that increments the value in the variable
count.
int count = 0;
17. Write a constant statement to hold the value of dis- final double discount
count, which is 15%.
18. Consider the following code segment.r = 5 x=2*π*r
h=9 y=x*r
Please select the most correct code fragment that will z = h * x
result in calculating the surface area of a cylinder, given surfaceArea = y + z
the equation:
Surface area = 2PIr^2 + 2PIrh
19. Consider the following code segment. 12
x=2
y=3
z=5
z=y
y=x*z
x=z
z=y
x=y+z
z=x/y
y=x
After the above code is executed, what is the value of
y?
1. Which of the following lines of code correctly writes System.out.println("Hel-
"Hello" to the screen. lo");
2. Fill in the blanks of the code below : main( Public, static, void, String[]
args){
3. The class name does not have to be the same as the False
file name
4. The command to compile a Java program is: Java
Hello.java.
5. Explain the steps that need to happen to take code 1. Code is written
from it being written to it running and producing out- 2. Code is compiled
put. 3. The byte code is read
6. What does the virtual machine do? Choose all answers 1. runs the class file
that apply. 2. runs the byte code
7. Logic errors are the hardest errors to find. T/F True
8. While running a program, it unexpectedly stops. What 1. runtime
type of error is that? Choose all answers that apply. 2. logic
9. Write the algorithm for the following computer prob- Set ASSESS_PERCENT =
lem: 0.22
Bear Corporation needs a program to calculate their Enter month1Sales,
quarterly assessment fee. They will total the sales for month2Sales,
the past quarter (a three month period) and the pay Month3Sales
22% of the total sales as their quarterly assessment Calculate totalSales by
fee. adding month1Sales,
month2Sales,
Month3Sales
, Calculate assessmentFee
by totalSales * AS-
SESS_PERCENT
Output assessmentFee
10. What is a variable? Choose all parts below that are 1. can change
relevant. 2. memory location
3. named
11. Name two primitive Java data types that represent int, byte, short, long
whole numbers.
12. Name two primitive Java data types that represent float, double
floating point numbers.
13. For each error shown below match it to the correct out- 1. Compile-time error
put: a compile-time error, run-time error, or no error. 2. run-time error
3. compile-time error
1. System.out.Println("Greetings, Planet Earth!"); 4. compile-time error
2. System.out.println(); 5. compile-time error
3. float scale = 7854.345368564323; 6. no error
4. System.out.println("I love VCU!")
5. Double x = 43.454;
6. System.out.print(45 % 342);
14. What is displayed in the following code segment? 1. 5
int numerator = 34; 2. 4
int denominator = 6;
1. System.out.println(numerator / denominator);
2..out.println(numerator % denominator);
15. Comment
, A part of a program that contains information about
the program but has no effect when the program runs
is called a .
16. Given the following declaration statement, write a count++
statement that increments the value in the variable
count.
int count = 0;
17. Write a constant statement to hold the value of dis- final double discount
count, which is 15%.
18. Consider the following code segment.r = 5 x=2*π*r
h=9 y=x*r
Please select the most correct code fragment that will z = h * x
result in calculating the surface area of a cylinder, given surfaceArea = y + z
the equation:
Surface area = 2PIr^2 + 2PIrh
19. Consider the following code segment. 12
x=2
y=3
z=5
z=y
y=x*z
x=z
z=y
x=y+z
z=x/y
y=x
After the above code is executed, what is the value of
y?