java - Arrays Checking input -


so i'm trying check input , if entered integer not greater previous 1 should ask again. program checks if integer out of bounds , if it's not integer entered doesn't check if entered 1 greater previous one.

for (int = 0; < finalgrades.length; i++){     //check input integer     while(!input.hasnextint()){              system.out.print("please enter integers only: ");         input.next();     }      finalgrades[i] = input.nextint();     if(finalgrades[i] > 100 || finalgrades[i] < 0){              system.out.print("please enter integers between 0 , 100 only:");         finalgrades[i] = input.nextint();     }     if(finalgrades[i] < finalgrades[i-1]){         system.out.print("please enter integers in ascending order only: ");         finalgrades[i]= input.nextint();         continue;     }     } 

do error?. java.lang.arrayindexoutofboundsexception?

what mean "my bottom if statement not running properly"?.

if problem, see if below helps

when i=0

if(finalgrades[i] < finalgrades[i-1]) ==> if(finalgrades[0] < finalgrades[-1]), fail.

here complete code.

    (int = 0; < finalgrades.length; i++) {         // check input integer         while (!input.hasnextint()) {             system.out.print("please enter integers only: ");             input.next();         }          finalgrades[i] = input.nextint();         if (finalgrades[i] > 100 || finalgrades[i] < 0) {             system.out                     .print("please enter integers between 0 , 100 only:");             finalgrades[i] = input.nextint();         }         if (i > 0) {             if (finalgrades[i] < finalgrades[i - 1]) {                 system.out                         .print("please enter integers in ascending order       only: ");                 finalgrades[i] = input.nextint();                 continue;             }         }     } 

thanks,


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -