Home > Back-end >  How to find the next available position in an array to then accept input
How to find the next available position in an array to then accept input

Time:11-11

I have this method where it needs to find the next available row that can take in user input. This method is supposed to just find the next available row, but I'm having trouble understanding how to accomplish this. This is what I have so far.

public static int findNextPosition(String[][] loanArray){

for(int index = 0; index < loanArray.length; index  ){
    if(loanArray.length){
      return loanArray;
    }
}
return -1; // full loanArray

}

I tried this code and where i feel my problem is in my if statement but I'm honestly not sure how to go about creating this method.

I have to use an array and to summarize I need to find the next available row to insert user input. Thank you for your help!

CodePudding user response:

The if statement needs to become something along the lines of:

if(loanArray[index].length==0) return index;
  • Related