SAMPLE MIDTERM EXAM FOR CSC120 Practice on this exam with only paper and pencil; do not use your notes or book. 1. Describe three ways in which comments can be included in a Java program. 2. Write down 10 key words in Java. Explain what they are good for. 3. Identifiers are the names used to specify different elements of a Java program, such as a class, method, or variable. Explain why the following are legal or illegal identifiers 3days Threedays threeDays three days break break2 days+3 _days 4. Explain the difference between the two operators = and == 5. What are the values of the Java expressions true && false false && true true || false 6. Rewrite the following loop, using a while statement for ( i = 0; i < 20; i++){ sum = sum + i; } 7. How many comparisons and how many copies are required to sort the array {7, 3, 66, -5, 22, -77, 2} using the Selection Sort? 8. What is printed by the following program? class Problem8 { public static void main(String[] args) { int[] data = { 1, 3, 5, 7, 9, 11 }; int sum = 0; for (int i = 1; i < data.length; i++) { sum = sum + (data[i] + data[i-1]); System.out.println("sum = " + sum); } } } 9. Write a program to print out the values of the function f(x) = x*x -2.0 for the values of x=0.0 to x=2.0 in steps of 0.1. Your program should contain a method that returns value of the function. 10. Write a program that asks the user to enter an integer, read the users input, and tell the user whether the number entered is even or odd. 11. What is printed by the following program? public class Star{ public static void main(String[] args) { int line; for ( line = 1; line <= 6; line++ ) { stars( line ); } } static void stars(int numberOfStars) { for (int i = 0; i < numberOfStars; i++) { System.out.print('*'); } System.out.println(); } }