Guest User

Untitled

a guest
Dec 2nd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class Advent2 {
  2.  
  3.     public static int getSurfaceArea(String input) {
  4.         int area = 0;
  5.         int[] sides = getDimensions(input);
  6.         area = 2 * ((sides[0] * sides[1]) + (sides[0] * sides[2]) + (sides[1] * sides[2]));
  7.         area += sides[0] * sides[1];
  8.         return area;
  9.     }
  10.  
  11.     private static int[] getDimensions(String input) {
  12.         String[] temp = input.split("x");
  13.         int[] output = new int[3];
  14.         for (int i = 0; i < temp.length; i++) {
  15.             output[i] = Integer.parseInt(temp[i]);
  16.         }
  17.         Arrays.sort(output);
  18.         return output;
  19.     }
  20.  
  21.     public static void main(String[] args) {
  22.         int total = 0;
  23.         try (Scanner scanner = new Scanner(new File("advent2.txt"))){
  24.             while(scanner.hasNextLine()) {
  25.                 total += Advent1.getSurfaceArea(scanner.nextLine());
  26.             }
  27.         } catch (FileNotFoundException e) {
  28.             e.printStackTrace();
  29.         }
  30.         System.out.println(total);
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment