电脑一安装java就死机_我写了一个java程序,一运行就死机

(2)编写程序计算三门课的平均成绩,要求应用程序分别用Java语言三种不同的循环语句实现,每门课的成绩用Math类的random()方法随机产生(random()产生的数值在0和1之间),成绩范围为4...

(2) 编写程序计算三门课的平均成绩,要求应用程序分别用Java语言三种不同的循环语句实现,每门课的成绩用Math类的random()方法随机产生(random()产生的数值在0和1之间),成绩范围为40~100。

类一:public class Math_Score {

private int[] Maths;

public Math_Score()

{

Maths = new int[20];

for (int i = 0; i < 20 ;i++)

Maths[i] = (int)Math.random() * 60 + 40;

}

public int Average_Maths()

{

int total = 0;

for (int i = 0; i < 20 ; i++)

total += Maths[i];

return (int)total/20;

}

}

类二:public class English_Score {

private int[] English;

public English_Score()

{

English = new int[20];

int i = 0;

do

English[i] = (int)Math.random() * 60 + 40;

while(i++ <20);

}

public int Average_English()

{

int total = 0;

for (int i = 0; i < 20 ; i++)

total += English[i];

return (int)total/20;

}

}

类三:public class Chinese_Score {

private int[] Chinese;

public Chinese_Score()

{

Chinese = new int[20];

int i = 0;

while (i < 20)

Chinese[i] = (int)Math.random() * 60 + 40;

}

public int Average_Chinese()

{

int total = 0;

for (int i = 0; i < 20 ; i++)

total += Chinese[i];

return (int)total/20;

}

}

类四:

public class Main {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Math_Score math = new Math_Score();

Chinese_Score chinese = new Chinese_Score();

English_Score english = new English_Score();

System.out.println("Math :" + math.Average_Maths());

System.out.println("Chinese :" + chinese.Average_Chinese());

System.out.println("English :" + english.Average_English());

}

}

请大家帮我看一下。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值