vladovip

Task “Converter” - Java - Alpha preparation

Jan 15th, 2022
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 positive number");
  17.         }
  18.  
  19.  
  20.     }
  21.  
  22. }
  23.  
RAW Paste Data