Java Programming

   
 

Gallons To Liters

 

import java.util.Scanner;// the Scanner method is used to get user input


public class GallonsToLiters {


public static void main(String[] args) {

Scanner scangallons = new Scanner(System.in);// create a new scanner object called scangallons

        int gallons = 0; // define variables and initialize values for both

        double liters = 0;

        System.out.println("Enter the number of gallons"); // prompt the user to enter the number of gallons

        gallons = scangallons.nextInt(); // assign the value the user input to the gallons variable.

        liters = gallons * 3.7854;  // calculate the number of liters

        

     

        System.out.println(gallons + " gallons is equal to " + liters + " liters.");

        // print the output to the screen.

}


}