Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class mpg {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- DecimalFormat format = new DecimalFormat("###,###,##0.0");
- double init, fin, gal, mpg;
- System.out.println("Welcome to the Miles per Gallon Calculator!");
- init = 12;
- while (init >= 0){
- System.out.print("\nEnter the INITIAL ODOMETER READING or a negative number to STOP: ");
- init = scan.nextDouble();
- if(init >= 0){
- System.out.print("\nEnter the FINAL ODOMETER READING: ");
- fin = scan.nextDouble();
- System.out.print("\nEnter the number of GALLONS OF GAS used: ");
- gal = scan.nextDouble();
- mpg = (fin-init)/gal;
- System.out.print("\n\tMiles per Gallon: " +format.format(mpg) + "\n");
- }
- }
- System.out.println("\nBYE!!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment