java - 方法完成后程序继续运行

标签 java compilation

我做了一个简单的程序,有两个类。该方法工作正常,但它在完成我的方法后继续运行,导致在输出中看到这一点,我不知道为什么:

enter image description here

最佳答案

您的myArrayOne 方法会调用自身。这就是无限递归的问题。

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

这可能是您想要完成的:

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

关于java - 方法完成后程序继续运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40585718/

相关文章:

c++ - 使用 visa 编译 dll/exe - 链接失败

java - thymeleaf th :each filtered with th:if

java - 有没有办法在java中模拟属性选择器?

compilation - 函数式语言天生就慢吗?

android - 错误 :Execution failed for task ':app:dexDebug' after importing project from Eclipse to Android Studio

C:从文件输入排序,收到大量编译错误

java - 如何根据给定的主题类型初始化复杂对象模型的属性?

java - FreeTTS 可移植性问题

java - 如何在SMSLib中获取发件人电话号码?

C++:为什么不能编译?