Sunday, August 24, 2014

MileAge

Class Name: MileAge. Translate the algorithm below into Java. Don’t forget to declare variables before they are used.

import java.util.Scanner;
public class MileAge {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
       
        double miles=0;
        double gallons=0;
        double tot=0;
       
        System.out.print("This program will calculate mileage.");
        System.out.print("\nEnter miles driven: ");
        miles=input.nextInt();
        System.out.print("Enter gallons used: ");
        gallons=input.nextInt();
       
        tot = miles/gallons;
       
        System.out.print("Miles per Gallon: "+tot+" mi/gal");
    }
}

No comments:

Post a Comment

advertisement