AP® Computer Science A

Name Date Quiz 1-1

CHAPTER 1

What is the output to the following Java code? Place your answers in the corresponding spaces below. public static void main(String [] args){ final int JUNK = 13; int j, k = 21, m = 4; double x = 2.5, y; String s1 = "APCS", s2 = "Go Spartans"; // # 1 System.out.println(s1.length() + s2.length()); // # 2 System.out.println((s1.length() + k) % m); // # 3 System.out.println(5 * k % 100 - 4 * x); // # 4 System.out.println((s1.substring(2) + s2.substring(3,5))); // # 5 System.out.println((s2.charAt(m))); // # 6 System.out.println(s2.indexOf(s1.charAt(3))); // # 7 System.out.println(JUNK / k + x); } 1. 2. 3. 4. 5. 6. 7.

8. Why would the following statement be illegal in the above program? JUNK = k + 3 * m % 1;

9. Why would the following statement be illegal in the above program? j = 3 + k / m * x;

10. What range of numbers would be produced by the following statement? (int)(Math.random() * 9)

Sign up to vote on this title
UsefulNot useful