我正在尝试检查数组是否已满,并打印出无法输入更多书籍的用户.
I am trying to do check if an array is full and print out to the user he is unable to enter more books.
static Object[][] books=new Object[2][];我正在向用户询问3个值,并将其存储到另一个名为行"的数组中.
I am asking 3 values from the user and am storing to another array called "row".
Object[]row=new Object[3];此后,我遍历books数组,并检查其中是否具有空值,并使用给定的用户值添加"row"数组.问题是输入两行值后,如果books数组已满,我无法给出任何反馈.
After that i loop through the books array and check if it has a null value inside of it and add the "row" array with the given values of the user. the problem am having is i cant give any feedback if books array is full after entering two rows of values.
boolean empty=false; while(empty==false){ for (int i = 0; i < books.length; i++) { if(books[i]==null){ books[i]=row; empty=true; break; } } } 推荐答案为什么没有变量
int bookCounter = 0;您可以在每次添加/删除书籍时增加/减少,然后对照最大书籍数(我认为是 books.length )进行检查
which you can increase/decrease everytime you add/delete books and then just check it against your max number of books (which I assume is books.length)
通过这种方式,您不需要遍历数组,这效率不高.
In this way you don't need to loop over the array, which is not efficient.
更多推荐
检查数组是否已满
发布评论