vladovip

Converttor Fuel Consumption_Java

Jan 6th, 2022 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Converter {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner input = new Scanner(System.in);
  10.         String consumptionInMiles = input.nextLine();
  11.         int consumptionInMilesNumber= Integer.parseInt(consumptionInMiles);
  12.         if ( 1 <= consumptionInMilesNumber &&  consumptionInMilesNumber <=100 ){
  13.             double consumptionLitters = Math.floor((4.54 / (consumptionInMilesNumber*1.6))*100);
  14.             System.out.printf("%.0f litres per 100 km", consumptionLitters);
  15.         } else {
  16.             System.out.println(" miles per gallon have to be positive number");
  17.         }
  18.  
  19.  
  20.  
  21.     }
  22.  
  23. }
  24.  
Add Comment
Please, Sign In to add comment