Advertisement
du4ko

Beers

Jun 8th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package Beers;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Beers {
  6.  
  7.         public static void main(String[] args) {
  8.                 Scanner input = new Scanner(System.in);
  9.                 String currentInput;
  10.                 int result = 0;
  11.                 do  {
  12.                         currentInput = input.nextLine();
  13.                         String[] currentInputArray = currentInput.split(" ");
  14.                         if (currentInputArray[currentInputArray.length-1].equals("beers")) {
  15.                                 result += Integer.parseInt(currentInputArray[0]);
  16.                         }
  17.                         if(currentInputArray[currentInputArray.length-1].equals("stacks")){
  18.                                 result += (Integer.parseInt(currentInputArray[0]) * 20);
  19.                         }
  20.                 } while((currentInput.equals("End"))==false);
  21.                
  22.                 int stacks = result / 20;
  23.                 int beers = result % 20;
  24.                 System.out.println(stacks + " stacks + " + beers+ " beers");
  25.         }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement