CMPS 144 Fall 2023
|
Name ________________________ |
From the point of view of an instance of the java.util.Scanner class, a token within a String s is a substring of s that
To keep things simple, assume here that the only whitespace character that appears in strings of interest is the space character (i.e., ' '). (Which is to say that you can assume that neither the TAB character nor the newline character is present.)
1 2 012345678901234567890123 ------------------------ The bear in the hat. |
Supply the missing bodies of at least two of the methods whose headings appear below (one on each side of the page), which can be used to find, within a given string, where a specified token begins and ends. The intent is that the k-th token of string s should be the result of the call
/* Returns the smallest-numbered index, not less ** than k, of a non-space character within s. ** If s has no non-space characters, s.length() ** is returned. */ static int indexOfNonSpace(String s, int k) { } |
/* Returns the smallest-numbered index, ** not less than k, of a space character ** within s. If s has no space characters, ** s.length() is returned. */ static int indexOfSpace(String s, int k) { } |
/* Returns the position, within the given string, at which its k-th token begins. */ public int startsAt(String s, int k) { } |
/* Returns the position, within the given string, at which its k-th token ends. */ public int endsAt(String s, int k) { } |