package s2;
public class test4 {
public static void main(String args[]) {
/*4、计算蔬菜总价
为了丰富群众菜篮子,平抑菜价,相关部分组织了蔬菜的调运。
今某箱中有多个品种的蔬菜。蔬菜的单价(元/公斤)存放在price数组中,
蔬菜的重量(公斤)存放在weight数组中。下面的代码计算该箱蔬菜的总价,试完善之。*/
double []price={1,2,3,4,5};
double []weight={1,2,3,4,5};
test4 t=new test4();
double x=t.getTotal(price,weight);
System.out.println(x);
}
public static double getTotal(double[] price, double[] weight)
{
double x = 0;
for(int i=0; i<price.length; i++) //price.length 求price数组的长度
{
x=x+ price[i] * weight[i];
}
return x;
}
}
public class test4 {
public static void main(String args[]) {
/*4、计算蔬菜总价
为了丰富群众菜篮子,平抑菜价,相关部分组织了蔬菜的调运。
今某箱中有多个品种的蔬菜。蔬菜的单价(元/公斤)存放在price数组中,
蔬菜的重量(公斤)存放在weight数组中。下面的代码计算该箱蔬菜的总价,试完善之。*/
double []price={1,2,3,4,5};
double []weight={1,2,3,4,5};
test4 t=new test4();
double x=t.getTotal(price,weight);
System.out.println(x);
}
public static double getTotal(double[] price, double[] weight)
{
double x = 0;
for(int i=0; i<price.length; i++) //price.length 求price数组的长度
{
x=x+ price[i] * weight[i];
}
return x;
}
}
634

被折叠的 条评论
为什么被折叠?



