Alright, exercise 4 has been graded. Not too many problems with the code but there were some consistent mistakes being made that should be pointed out. Syntax - many of you were forgetting semi-colons at the end of lines. It is alright to declare and initialize multiple variables on one line. This will compile. However, it is bad style to do this. While you may declare multiple variables on one line, it is generally a good practice to initialize only one per line. Comments, comments, comments. Many papers had none. The comments which were found on the page were written by Kiri to explain what you needed to do. These were not there to comment the code which you wrote in. If the exercise had received a grade for style, 90% of the class would have gotten a zero. For loops. Obviously, these were the heart of exercise 4. And for those of you who continue in CS, for loops will follow you through Object Oriented Programming. Here are some basic pointers: for (init; cond; incr) { /*body*/ } Here's something neat that no one knew about. You can use the empty statement in place of any of these. so, the code: for (int i = 0; i <= 10; i++) is the same as: int i = 0; for (; i <= 10; i++); therefore, if you have i already initialized before the for loop, you don't need to reinitialize it in the init statement. Just leave it empty :) You can do this for conditions, too. for (int i = 0; ; i++) {} is an infinite loop that will continue to increment i, and will only terminate if there is a break; or System.exit(); in the loop. for (int i = 0; i <= 10;) {} is an infinite loop that will keep i at 0 and will only break if the above commands are in the loop, or if i is set to a value >10 in the loop. Once you have the for loop down, you must also straighten out what values go where. Several of you mixed up the conditions, so make sure what you are putting in the loop makes sense. One example was: num = Savitch.readLineInt(); for (int num = 1; num != 0; num--) As you can see if you examine this carefully, the data stored in num is replaced with 1, and the loop only runs once, instead of the number that the user specified. Be careful with your loop conditions, or later on you will be getting very strange (and often hard to find) errors while running your programs with loops. :o Lastly, in calculating the percentage - chances were very likely that you would end up with a decimal value. In addition, remember the precedence that Kiri talked about in lecture. heads / num_flips * 100 will always give 0 unless heads == num_flips Therefore, you needed to fix this in the following way: heads / ((double) num_flips) * 100 this would give the correct value for percentage. Notice that the cast is performed first, and then when the div is performed, it uses float and not integer division. It was alright if you left out the 100, that was a matter of personal taste. As always, if you have questions, please see me during office hours, and I will be more than happy to go over anything from the course, as well as anything outside of the course, with you. - b