Advertisement
Musical_Muze

Day 1, Part 1

Dec 2nd, 2019
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. import java.Math;
  2. import java.util.Scanner;
  3. import java.io.*;
  4.  
  5. public class Fuel {
  6.    
  7.     public static void main (String[] args) throws IOException{
  8.        
  9.         int sum = 0;
  10.        
  11.         File input = new File("modules.txt");
  12.         Scanner modules = new Scanner(input);
  13.        
  14.         FileWriter output = new FileWriter("answer.txt");
  15.        
  16.         while(modules.hasNext()){
  17.             int mass = modules.nextInt();
  18.             double fuel = (mass / 3);
  19.             fuel = (Math.round(fuel))-2;
  20.             sum += fuel;
  21.         };
  22.        
  23.         System.out.println("The total fuel required is " + sum);
  24.         output.write(sum);
  25.    
  26.     };
  27.    
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement