Java String Tokens

  • + 2 comments

    when we do:

    s = scan.next()
    

    s.length() is definitely greater than 1 as per constraints

    but after:

    s = s.trim()
    

    all leading and trailing whitespaces are removed

    hence if s = " " i.e. only white spaces then

    s.trim() will make s.length() == 0

    as all white spaces are removed.

    In 9th test case if you observe there is

    non empty string filled with white spaces

    as input hence I had to put that

    if condition.