简体   繁体   English

方法完成后程序继续运行

[英]Program continues to run after method is finished

I have made a simple program, with two classes. 我编写了一个简单的程序,有两个类。 The method works fine, however it continues to run after completing my method resulting in this being seen in the output and I have no idea why: 该方法运行良好,但是在完成我的方法后仍继续运行,导致在输出中看到该结果,我不知道为什么:

在此处输入图片说明

Your myArrayOne method calls itself. 您的myArrayOne方法会自行调用。 That's the problem with infinite recursion. 这就是无限递归的问题。

public static int myArrayOne() {
        // that's the problem
        return myArrayOne();
}

That is probably what are you trying to accomplish: 那可能就是您要完成的工作:

 // void --> List<Integer>
 // static 
 public List<Integer>  myArrayOne() {
     ArrayList<Integer> packOfCards = new ArrayList<Integer>();
     Random rand = new Random();

     for (int j = 0; j<5; j++)
     {
         pick = rand.nextInt(10);
         packOfCards.add(pick);
     }

     // myArrayOne(); --> packOfCards
     return packOfCards;
}

public static void main(String[] args) {
      myattributes attributes = new myattributes();
      List<Integer> values = attributes.myArrayOne(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM