键入购物的金额 输出每一笔的金额和总金额

 1 import java.util.Scanner;
 2 public class LianXi6{
 3  public static void main(String[] args){
 4   double total = 0;
 5   //创建一个长度为5的数组
 6   double[] price = new double[5];
 7   //导入  Scanner  类  键盘输入
 8   Scanner sc = new Scanner(System.in);
 9   for(int i=0;i<price.length;i++){
10    System.out.print("请输入第"+(i+1)+"笔购物的金额:");
11    // 通过Scanner类 接受键盘输入的内容
12     price[i] = sc.nextDouble();
13     // 通过for循环  数组中的元素累加
14     total += price[i];
15   }
16   System.out.println("序号		价格(元)");
17   for(int i=0;i<price.length;i++){
18    System.out.println((i+1)+"		"+price[i]);
19   }
20   System.out.println("总价为		"+total);
21  }
22 }
原文地址:https://www.cnblogs.com/zhangmenghui/p/10502589.html