This simple program will ask user to enter their mile driven and the gallon of gas, and the program will calculate the MPG.
Sample Output:
Sample Output:
Sample Source Code:
public class MPG
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter Mile driven: ");
double mile = input.nextDouble();
System.out.print("Enter Gallon of gas: ");
double gallon = input.nextDouble();
double mpg = mile / gallon;
System.out.print("your mile/gallon "+ mpg);
}
}
public class MPG
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter Mile driven: ");
double mile = input.nextDouble();
System.out.print("Enter Gallon of gas: ");
double gallon = input.nextDouble();
double mpg = mile / gallon;
System.out.print("your mile/gallon "+ mpg);
}
}

0 comments:
Post a Comment