java - StringOutofBoundsException -
when put in while loop n, out of bounds exception appears, if take out it's perfect. i'm add data array later on, it's producing error .... string day = date.substring(0, spacepos); the exception follows: exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: -1 @ java.lang.string.substring(unknown source) @ helloworld.main(helloworld.java:21) scanner userinputscanner = new scanner(system.in); // i/o stream string months[] = {"jan","feb","mar","apr","may","jun","jul","aug","sept","oct","nov","dec"}; // months compare int n = userinputscanner.nextint(); while(n != 0) { system.out.print("enter data: "); string date = userinputscanner.nextline(); // input , store data string output; ...