當前位置:首頁 » 編程語言 » 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());
}
}

熱點內容
手機無線存儲器 發布:2025-09-14 14:18:24 瀏覽:975
將編程納入 發布:2025-09-14 14:08:20 瀏覽:400
android進度條使用 發布:2025-09-14 14:01:06 瀏覽:852
怎麼看伺服器哪些埠沒有被佔用 發布:2025-09-14 14:01:06 瀏覽:228
星際方塊伺服器家園世界如何禁足 發布:2025-09-14 14:00:52 瀏覽:344
我的世界如何創建一個有模組的伺服器 發布:2025-09-14 13:42:40 瀏覽:330
安防場景如何選擇伺服器 發布:2025-09-14 13:20:48 瀏覽:741
php數組獲取鍵 發布:2025-09-14 13:20:47 瀏覽:857
蘋果和安卓哪個適合跑滴滴 發布:2025-09-14 13:07:55 瀏覽:995
怎麼訪問wamp 發布:2025-09-14 12:26:55 瀏覽:822