java - findWithinHorizon - how's it working? -
there code myscanner.findwithinhorizon.charat(1). want type in word , second (third, fourth, whatever) letter word. if there's .charat(0), works , returns first letter.
whenever set different .charat(), doesn't work: exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: 1
public static void main(string[] args) { char c1; scanner myscanner = new scanner(system.in); system.out.print("write something: "); c1 = myscanner.findwithinhorizon(".", 0).charat(1); system.out.println(c1); } thanks.
. regex means "1 char, whatever is". you're looking next char. returned string contains single char. attempting char @ index 1 throwing exception.
to next word, use scanner.next().
Comments
Post a Comment