Answer:
import java.util.Scanner;
public class qs {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double price;
do {
System.out.print("Enter the price for a gallon of gas: ");
while (!input.hasNextDouble()) {
System.out.println("That's not a number!");
input.next(); // this is important!
}
price = input.nextDouble();
} while (price < 0);
System.out.println("The price is " + price);
}
}