Reputation: 31
like my question is that why is it not able to print even the hi - print statement inside?
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);
}
}
}
Upvotes: 0
Views: 52
Reputation: 1478
You main
method does not contain anything.
public static void main(String arg[]) {
// NOTHING HERE
}
So to be able to print "hi" you should declare and initialize your Processor
class inside your main method by doing this.
public static void main(String arg[]) {
Processor p = new Processor();
}
OUTPUT:
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
Upvotes: 3