Question 991
Widget,5,3.50Gadget,10,2.25Each line has a name, quantity, and unit price. What is printed?
double total = 0;
while (sc.hasNext()) {
String[] parts = sc.nextLine().split(",");
int qty = Integer.parseInt(parts[1]);
double price = Double.parseDouble(parts[2]);
total = total + qty * price;
}
sc.close();
System.out.println(total);Answer images

