arrays - java arrayoutofbounds exception error when program together -


i doing assignment , have several simple string manipulations. think have last 1 figured out, , works itself, not work when put other string manipulations, giving me arrayoutofbounds exception error. advice? here small code made

  public static void main (strings[] args) {     scanner sc = new scanner(system.in);     string thesentence = sc.nextline();     string [] thewords = thesentence.split(" ");     arrays.sort(thewords);     system.out.println(thewords[1]);     system.out.println(arrays.tostring(thewords)); } 

this not work when put rest of code though works itself. reference, code supposed take in small sentence , give me smallest word lexicographically. ex: input: "4 wait this" output "is"

the code assuming thewords have @ least 2 elements in it. if sentence provided user not have spaces, thewords never element in position 1 , program crash on system.out.println(thewords[1]);


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -