为什么我不能在这里打印我的对账单或任何东西?

就像我的问题是,为什么它甚至不能打印里面的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);

        }


             }

    }


Qyouu
浏览 86回答 1
1回答

慕姐4208626

U 方法不包含任何内容。mainpublic static void main(String arg[]) {&nbsp; &nbsp; &nbsp;// NOTHING HERE}因此,为了能够打印“hi”,您应该通过执行此操作在main方法中声明并初始化类。Processorpublic static void main(String arg[]) {&nbsp; &nbsp; &nbsp;Processor p = new Processor();}输出:hi0Process id&nbsp; Priority&nbsp; &nbsp; burst length0&nbsp; &nbsp;6&nbsp; &nbsp;989Process id&nbsp; Priority&nbsp; &nbsp; burst length9&nbsp; &nbsp;6&nbsp; &nbsp;422Process id&nbsp; Priority&nbsp; &nbsp; burst length2&nbsp; &nbsp;3&nbsp; &nbsp;849Process id&nbsp; Priority&nbsp; &nbsp; burst length9&nbsp; &nbsp;2&nbsp; &nbsp;865Process id&nbsp; Priority&nbsp; &nbsp; burst length5&nbsp; &nbsp;4&nbsp; &nbsp;70
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java