就像我的问题是,为什么它甚至无法打印里面的 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);
}
}
}
最佳答案
您的main
方法不包含任何内容。
public static void main(String arg[]) {
// NOTHING HERE
}
因此,为了能够打印“hi”,您应该通过执行此操作在主方法中声明并初始化您的 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
关于java - 为什么我不能在这里打印我的声明或任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112280/