简体   繁体   中英

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. 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(); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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