letsdoitjava

GaseMilage Practice

Jul 8th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class GasMileage {
  3.     public static void main(String[] args)
  4.     {
  5.         Scanner scan = new Scanner(System.in);
  6.        
  7.         System.out.println("How man miles have you driven?");
  8.         float milesDriven = scan.nextFloat();
  9.            
  10.         System.out.println("How many gallons did you use?");
  11.         float gasGallons = scan.nextFloat();
  12.        
  13.         float result = milesDriven / gasGallons;
  14.         System.out.printf("Your gas mileage is: %.9f%n", result);
  15.        
  16.         if(result < 30)
  17.         {
  18.             System.out.println();
  19.             System.out.println("You are getting good gas mileage!");
  20.         }
  21.         else if(result > 30)
  22.         {
  23.             System.out.println();
  24.             System.out.println("This is not good gas mileage, perform maintenance on vehicle.");
  25.         }
  26.         scan.close();
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment