Ex9CommonMistakes

Ex9CommonMistakes - return false; } if (grade >=...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Example 8b: What does this print out? int count = 1; while (count < 10); { int count2 = count; while (count2 < 10) { System.out.print(" "); count2 = count2 + 1; } count2 = 0; while (count2 < (count*2-1)) { System.out.print("*"); count2++; } System.out.print("\n"); count++; } Example 9: Find The Implementation Mistakes Gradebook.java:11: 'else' without 'if' else if (grade < 60); System.out.println("Sorry, you did not pass the course."); else System.out.println("Congratulations, you passed the course."); ********************************************************************* if (grade >= 90) System.out.print("Wow! You got an A! Are you interested"); System.out.println(" in becoming a CS major?"); ***************************************************************** Gradebook.java:55: unreachable statement System.out.println("Congratulations, you passed the course."); Gradebook.java:57: missing return statement } if (grade < 60) { System.out.println("Sorry, you did not pass the course.");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return false; } if (grade &gt;= 60) { return true; System.out.println(&quot;Congratulations, you passed the course.&quot;); } Fill in the correct code for the above example: if (grade &lt; 60) { System.out.println(&quot;Sorry, you did not pass the course.&quot;); return false; } { } ***************************************************************** if ((grade &gt;= 80) || (grade &lt; 90)) System.out.println(&quot;B&quot;); ***************************************************************** Problem statement: Calculate the average score of a set of scores. int count = 0; double total = 0; double score; boolean finished = false; while (finished == true) { System.out.print(&quot;Enter next test score: &quot;); score = input.nextDouble(); if (score &lt; 0) finished = true; else { total = total + score; count = count + 1; } } System.out.printf(&quot;Average is: %f\n&quot;,total / (double)count);...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Ex9CommonMistakes - return false; } if (grade &amp;amp;gt;=...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online