Tuesday, September 30, 2014

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 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);




 }

}

Tagged:

0 comments:

Post a Comment

Zul Ameen Blog © 2013 | Powered by Blogger | Blogger Template by DesignCart.org