Why do you have 2 read statements?
This works fine on my comp (Assuming 5 gallons is actually 22.5 litres)
I must look into scanners more, when I was learning Java at Uni we used buffered input readers but these are much easier to use...
This works fine on my comp (Assuming 5 gallons is actually 22.5 litres)
Code:
import java.util.Scanner;
public class GallonsToLitres
{
public static void main(String[] args)
{
System.out.println("How many gallons do you want to be converted?");
Scanner input = new Scanner(System.in);
int gallons = input.nextInt();
System.out.println(gallons + " gallons is " + (gallons * 4.5) + " litres");
}//End of main()
}//End of class
I must look into scanners more, when I was learning Java at Uni we used buffered input readers but these are much easier to use...
Last edited: