Code: Select all
/*
Project 1-1
This program converts gallons to liters.
Call this program GalToLit.java.
*/
class GalToLit {
public static void main(String args[]) {
double gallons; // holds the number of gallons
double liters; // holds conversion to liters
gallons = 10; // start with 10 gallons
liters = gallons * 3.7854; // convert to liters
System.out.println(gallons + " gallons is " + liters + " liters.");
}
}
I've modified it as this. To get user inputs. I know one way of giving inputs That is giving values via parameters Not a so clever coding isn't it?
Code: Select all
class GalToLit{
public static void main(String args[]){
double gallons,liters;
gallons = Double.parseDouble(args[0]);
liters = gallons*3.7854;
System.out.println(gallons+" gallons is "+ liters + " liters. ");
}
}
How is it?
PS: I had to add codes without syntax heightening since that function doesn't work. May be because of the server changing