This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 1 NAME (PRINT LEGIBLY!)___________________________________________ (last, first) This 90-minute exam has 8 questions (numbered 0..7) worth a total of 100 points. We suggest that you spend a few minutes looking at all questions before beginning so that you can see what is expected. Budget your time wisely. Use the back of the pages, if you need more space. Question 0 (2 points). Write your netid and your name, legibly, at the top of each page. Question 1 (18 points). (a) Write a declaration for a local String variable line . It should not give an initial value to line . (b) Write a sequence of Java statements to print the number of characters at the beginning of line that are the same as the first character in line . Assume that line contains at least 1 character. Dont write a complete method; just write the statements. Declare any variables that you use (except variable line ). You will need to write a loop. You dont have to write an invariant if you dont want to. Remember that line.charAt(k) yields the character at index k . Examples: If line is "aaabcd" , the output is 3 . If line is "abcd" , the output is 1 . If line is "a" , the output is 1 . If line is "aabaaa" , the output is 2 . (Later occurrences of the same character do not count.) If line is "aaAaaa" , the output is 2 . (Upper-case and lower-case are different.) CS100J Prelim II, 21 Oct. 2003 CORNELL NETID ______________________ 2 Question 2. (12 points). Write down the sequence of steps that are performed in executing the procedure...
View Full Document
This note was uploaded on 06/01/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).
- Fall '07