package helloworld; import java.util.Scanner; public class GouWu { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("依次输入三个商品名称 单价 数量 "); //第一个商品名称,单价,数量 String name1 = input.next(); double pri1 = input.nextDouble(); int num1 = input.nextInt(); //第二个商品名称,单价,数量 String name2 = input.next(); double pri2 = input.nextDouble(); int num2 = input.nextInt(); //第三个商品名称,单价,数量 String name3 = input.next(); double pri3 = input.nextDouble(); int num3 = input.nextInt(); System.out.println("支付的金额:"); int money = input.nextInt(); input.close();//关闭输入流 double mon1,mon2,mon3;//分别的商品总额 double sum,change; mon1 = pri1*num1; mon2 = pri2*num2; mon3 = pri3*num3; sum = mon1+mon2+mon3; if(money<sum){ System.out.println(" 支付金额不够.");} else{ change = money-sum; System.out.println("__________________________________"); System.out.println("***********消费单****************"); System.out.println("购买物品 单价 个数 金额"); System.out.print(name1+" ¥"+pri1+" "+num1+" ¥"+mon1+" "); System.out.print(name2+" ¥"+pri2+" "+num2+" ¥"+mon2+" "); System.out.print(name3+" ¥"+pri3+" "+num3+" ¥"+mon3+" "); System.out.println("=================================="); System.out.println("消费总金额"+" ¥"+sum); System.out.println("实际交费"+" ¥"+money); System.out.println("找钱"+" ¥"+change);} } }