grach

FuelTank

Mar 26th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FuelTank {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String fuelType = scan.nextLine().toLowerCase();
  8.         int liters = Integer.parseInt(scan.nextLine());
  9.  
  10.         if (!fuelType.matches("diesel|gasoline|gas")) {
  11.             System.out.println("Invalid fuel!");
  12.         } else if (liters >= 25) {
  13.             System.out.printf("You have enough %s.", fuelType);
  14.         } else if (liters >= 0) {
  15.             System.out.printf("Fill your tank with %s!", fuelType);
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment