Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.Math;
- import java.util.Scanner;
- import java.io.*;
- public class Fuel {
- public static void main (String[] args) throws IOException{
- int sum = 0;
- File input = new File("modules.txt");
- Scanner modules = new Scanner(input);
- FileWriter output = new FileWriter("answer.txt");
- while(modules.hasNext()){
- int mass = modules.nextInt();
- double fuel = (mass / 3);
- fuel = (Math.round(fuel))-2;
- sum += fuel;
- };
- System.out.println("The total fuel required is " + sum);
- output.write(sum);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement