for(元素类型 元素变量 : 遍历对象) {
// 循环体
}
double[] prices = {29.9, 39.8, 15.5, 88.0, 12.3}; double total = 0.0;
for(double price : prices) {
total += price;
System.out.println("当前商品价格:" + price);
} System.out.println("商品总价:" + total);
List
System.out.println(name);
}
你可能想看: