java - How would I display the position of an element in an array? -


my dilemma after user inputs number, number checked see if it's in array, if i'll let them know in array along position of said number. have prompts user number, after arrayindexoutofboundsexception error.

here's have far:

int [] igrades = new int [30];        system.out.print ("enter grades, when you're done input (-1) ");       (int i=0; i<igrades.length;i++)       {           igrades [i]= kb.nextint();           if (igrades [i]< 0)           {               break;           }       }       system.out.print ("\nenter grade check if it's in array");       ival = kb.nextint();       for(int i=0; i<=igrades.length; ++i)        {             if(ival == (igrades[i]))             {                 found = true;                 for(int j=0; j<=igrades.length; ++j)                 {                     igrades[j]=j+1;                 }                 break;             }         }        if (found == true)       {           system.out.println(ival + " in array @ position ");       }       else       {          system.out.println(ival + " not in array.");       }    }    

any assistance great.

the problem in second for loop. this

      for(int i=0; i<=igrades.length; ++i) 

change <= <.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -