import java.util.Scanner; public class A02 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input= new Scanner (System.in); double number [] = new double [5]; double sum=0; for (int i = 0; i < number.length; i++) { System.out.println("请输入第"+(i+1)+"笔购物:"); number[i]=input.nextDouble(); } System.out.println("序号\t金额(元)"); for (int i = 0; i < number.length; i++) { System.out.println((i+1)+"\t"+number[i]); sum+=number[i]; } System.out.println("总金额\t"+sum); } }
java-第七章-数组-购物金额结算
时间: 2025-01-02 06:47:24