Error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 -


i in first class of java programming , 1 of assignments given create value string displays in reverse order separated commas. know missing simple, after hours of trying don't know going wrong?

my code works, keep getting error message:

exception in thread "main" java.lang.arrayindexoutofboundsexception: -1      @ ip2_jolley.ip2_jolley.main(ip2_jolley.java:148)  three, two, 1 java result: 1 

this code using:

string[] f = {"one", "two", "three"}; if (f.length > 0) system.out.print (f[2]); (int = 1; < f.length; i--){     system.out.print(", " + f[i]);  } 

you start loop int = 1 , reduce 1 every loop result in being lower 0.

instead of using int = 1, want use int = f.length

edit

what wanted this:

  string[] f = {"one", "two", "three","four","five"};      //start @ f.length - 1, continue until there no item left     (int = f.length-1; >= 0; i--){          //print current item         system.out.print(f[i]);          //if not last item, print separator         if(i>0){             system.out.print(", ");         }     } } 

edited explanation


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -