Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Advent2 {
- public static int getSurfaceArea(String input) {
- int area = 0;
- int[] sides = getDimensions(input);
- area = 2 * ((sides[0] * sides[1]) + (sides[0] * sides[2]) + (sides[1] * sides[2]));
- area += sides[0] * sides[1];
- return area;
- }
- private static int[] getDimensions(String input) {
- String[] temp = input.split("x");
- int[] output = new int[3];
- for (int i = 0; i < temp.length; i++) {
- output[i] = Integer.parseInt(temp[i]);
- }
- Arrays.sort(output);
- return output;
- }
- public static void main(String[] args) {
- int total = 0;
- try (Scanner scanner = new Scanner(new File("advent2.txt"))){
- while(scanner.hasNextLine()) {
- total += Advent1.getSurfaceArea(scanner.nextLine());
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- System.out.println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment