就像我的问题是,为什么它甚至不能打印里面的hi-print语句?public class Processor { Random random = new Random();class Process { int proId, prior, BurstLength; } ArrayList<Process> processList;public static void main(String arg[]) {} public Processor() { System.out.println("hi"); processList = new ArrayList<>(); for (int i = 0; i< 5 ; i++){ Process newProcess = new Process(); int temp; l1:while(true){ int rand = 10 - 0; temp = random.nextInt(rand)+0; System.out.println(temp); for (Process p:processList) if (p.proId == temp) continue l1; break; } newProcess.proId = temp; newProcess.prior = (int)Math.round(Math.random()*9)+1; int range = 100 - 20 + 1; newProcess.BurstLength = random.nextInt(range) + 20; System.out.println("Process id\tPriority\tburst length"); System.out.println(newProcess.proId+"\t"+newProcess.prior+"\t"+newProcess.BurstLength); } } }
1 回答
慕姐4208626
TA贡献1852条经验 获得超7个赞
U 方法不包含任何内容。main
public static void main(String arg[]) {
// NOTHING HERE
}
因此,为了能够打印“hi”,您应该通过执行此操作在main方法中声明并初始化类。Processor
public static void main(String arg[]) {
Processor p = new Processor();
}
输出:
hi
0
Process id Priority burst length
0 6 98
9
Process id Priority burst length
9 6 42
2
Process id Priority burst length
2 3 84
9
Process id Priority burst length
9 2 86
5
Process id Priority burst length
5 4 70
添加回答
举报
0/150
提交
取消