Advertisement
dimipan80

Exam 1. Dozens of Eggs

Sep 16th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _1_DozensOfEggs {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         int countDozens = 0;
  10.         int countEggs = 0;
  11.         for (int i = 0; i < 7; i++) {
  12.             int count = scan.nextInt();
  13.             String measure = scan.next();
  14.             if (measure.equals("eggs")) {
  15.                 countEggs += count;
  16.             } else {
  17.                 countDozens += count;
  18.             }
  19.  
  20.             scan.nextLine();
  21.         }
  22.  
  23.         if (countEggs > 11) {
  24.             countDozens += countEggs / 12;
  25.             countEggs %= 12;
  26.         }
  27.  
  28.         System.out.printf("%d dozens + %d eggs%n", countDozens, countEggs);
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement