Advertisement
dimipan80

Exam 1. Count Beers

Sep 14th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _1_CountBeers {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         String inputLine = scan.nextLine().trim();
  9.  
  10.         int countStacks = 0;
  11.         int countBeers = 0;
  12.         String[] inputs;
  13.         while (!inputLine.equals("End")) {
  14.             inputs = inputLine.split(" ");
  15.             int count = Integer.parseInt(inputs[0]);
  16.             if (inputs[1].equals("beers")) {
  17.                 countBeers += count;
  18.             } else {
  19.                 countStacks += count;
  20.             }
  21.  
  22.             inputLine = scan.nextLine().trim();
  23.         }
  24.  
  25.         if (countBeers >= 20) {
  26.             countStacks += countBeers / 20;
  27.             countBeers %= 20;
  28.         }
  29.  
  30.         System.out.printf("%d stacks + %d beers%n", countStacks, countBeers);
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement