FOR条件生成无尽的打印输出。我真的不知道怎么回事。书籍中只有一个条目作为实例。我做错了什么?
package LOIoefeningen;
import java.util.ArrayList;
public class Handin
{
public static void main(String[] args)
{
String title = null;
String author = null;
Possessor Bookworm = new Possessor("Bookworm", new Books(title, author));
ArrayList<Books> book = new ArrayList<>();
for (int i = 0; i < book.size(); i++)
{
book.add(new Books("Pietje Puk", "Henri Arnoldus"));
System.out.println(book.get(i));
}
}
}
}
答案 0 :(得分:0)
您每次都在循环中添加一本新书。将book.add(new Books("Pietje Puk", "Henri Arnoldus"));
移到循环之前。