当前位置:首页 » 编程语言 » java死机

java死机

发布时间: 2025-03-02 17:24:58

⑴ 我写了一个java程序,一运行就死机

不仅Chinese_Score类中的死循环,还有(int) (Math.random() * 60) + 40
如果(int) Math.random() * 60+ 40,Math.random()的值[0,1)取整恒为0,你的平均值就永远为40,所以应:(int) (Math.random() * 60),具体如下:

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;
i++;
}
}

public int Average_Chinese() {
int total = 0;
for (int i = 0; i < 20; i++) {
total += Chinese[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 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 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());
}
}

热点内容
网易mc手机怎么免费开服务器 发布:2025-05-02 03:28:39 浏览:97
macpythongui 发布:2025-05-02 03:15:43 浏览:310
服务器地址校验 发布:2025-05-02 03:03:28 浏览:884
入户380v配电箱如何配置图 发布:2025-05-02 02:58:27 浏览:270
电脑挂国外服务器怎么操作 发布:2025-05-02 02:39:26 浏览:410
python重采样 发布:2025-05-02 02:38:51 浏览:849
海信新版电视的设置密码是什么 发布:2025-05-02 02:30:22 浏览:221
手机电脑服务器教程 发布:2025-05-02 02:29:09 浏览:311
ntko大文件上传 发布:2025-05-02 02:25:59 浏览:118
视觉算法简称 发布:2025-05-02 02:24:21 浏览:210