Use the String class's valueOf method on line 42 to convert a char to a String
After an isBlank() call, there is no need for an isEmpty() call (line 24).
Line 29 is confusing.
Varuna Seneviratna
Varuna Seneviratna wrote:@CareyBrown
Line 2 is a test to see how the program works if the whole string is alphabetical
Huh?
Line 2 is
i = j;
Varuna Seneviratna
Carey Brown wrote:Let's say we were dealing with int variables 'i' and 'j', if you wrote this
What would be the point of having line 1 if you are just going to throw the value away and replace it with the contents of 'j' on the very next line?
You have the same issue but with String variables.
Carey Brown wrote:I don't understand why you are going through all those painful steps with sub-strings. You could more easily use two indexes into the input String: begin and end. Increment these as needed and use charAt(idx) to compare the characters. The longest distance between begin and end would be your answer.
You could more easily use two indexes into the input String: begin and end. Increment these as needed and use charAt(idx) to compare the characters.
Varuna Seneviratna
Look at their documentation.Varuna Seneviratna wrote:. . . Are they are the same?
That doesn't add to the explanation, I am afraid.. . . What line 29 does is compare the last character in the subStr for alphabetical order with a character in the string that's currently going through the loop.
Campbell Ritchie wrote:Please don't edit old posts; that makes the thread difficult to follow and makes the line numbers appear wrong. I am refusing the first edit.
Please post the cleaned up code as a new post.
Campbell Ritchie wrote:Please explain what you are looking for. I can see, “abcdef,” which I think is an “unbroken alphabetical” substring, and I can also see, “bd'” which I think probably isn't “unbroken alphabetical”.
Please only post the code you are actually running; there is no point in posting commented‑out code. That makes the code very difficult to read.
Please format and indent the code correctly.
After an isBlank() call, there is no need for an isEmpty() call (line 24).
Line 29 is confusing. It looks as though you had stumbled upon a very inefficient way to iterate the String.
Varuna Seneviratna
Campbell Ritchie wrote:
Look at their documentation.Varuna Seneviratna wrote:. . . Are they are the same?
That doesn't add to the explanation, I am afraid.. . . What line 29 does is compare the last character in the subStr for alphabetical order with a character in the string that's currently going through the loop.
Varuna Seneviratna
Sorry if I wasn't clear.Varuna Seneviratna wrote:. . . I was responding to your reply.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |