Advertisement
kyamaliev

Java Exam 27.5.2014 Problem 1

May 27th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4. public class Problem1 {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         ArrayList<String> inputList = new ArrayList<>();
  8.         boolean ended = true;
  9.         while (ended) {
  10.             String temp = scan.nextLine();
  11.             if (temp.equals("End")) {
  12.                 ended = false;
  13.             }
  14.             inputList.add(temp);
  15.         }
  16.         int beers = 0;
  17.         int stacks = 0;
  18.         //System.out.println(inputList.get(0));
  19.         String[] temp = new String[2];
  20.         for (int i = 0; i < inputList.size()-1; i++) {
  21.             temp=inputList.get(i).split(" ");
  22.             if (temp[1].equals("stacks")) {
  23.                 stacks += Integer.parseInt(temp[0]);
  24.             }else{
  25.                 beers += Integer.parseInt(temp[0]);
  26.             }
  27.         }
  28.         if (beers>20) {
  29.             stacks += beers / 20;
  30.             beers = beers %20;
  31.            
  32.         }
  33.         System.out.println(stacks + " stacks + " + beers + " beers");
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement