1. 2 2. 56 4 6 8 10 12 14 3. 30 4. 40 20 30 10 20 5. 20 6. 0 10 7. yes 8. help no hello no help goodbye help why help blue blue blue blue 9. 12 (indentation is incorrect) 10. 0000000000 11. 2 -4 12. 1 3 -3 2 4 -2 3 5 -1 4 5 6 13. 19 5 14. The program counts the number of times the characters "." and "," are entered using the variable "punctuation", It counts the number of times a letter is entered using the variable "letters", and it counts the number of times a digit is entered using the variable "digits". All other characters are ignored. When the user enters the sentinel (the character '\'), the program stops reading characters and prints the three counts. 15. System.out.println("please enter a character followed by a number "); mystr = getkeybd.next(); character = mystr.chatAt(0); number = getkeybd.nextInt(); for (lines = 1; lines <= number; lines++) System.out.println(character); 16. totpay = 0; System.out.println("Hours: "; hours = getkeybd.nextInt(); while (hours >= 0) { System.out.println("Rate: $ "); rate = getkeybd.nextDouble(); pay = hours * rate; System.out.println("Employee pay is : $ " + pay); totpay += pay; System.out.println("Hours: "); hours = getkeybd.nextInt(); } System.out.println("Total payroll is $ " + totpay); 17. int numout, numsat, numunsat; int score; numout = numsat = numunsat = 0; System.out.println("Enter an exam score: "); score = getkeybd.nextInt(); while (score >= 0) { if (score >= 90) numout++; else if (score >= 70) numsat++; else numunsat++; System.out.println("Enter an exam score: "); score = getkeybd.nextInt(); } System.out.println("\nOutstanding scores: " + numout); System.out.println("Satisfactory scores: " + numsat); System.out.println("Unsatisfactory scores: " + numunsat);
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2013