Originally posted by Chas Martin:
... The thing I am stuck on is getting it to look at the strings and lexicographically compare two strings. There is a compare method but I cant figure out how to make it work...
The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Chas Martin:
I have this so far but Its skipping every other line
How do I make it hit every line.
Originally posted by Chas Martin:
Im not sure and I cant find any info that tells me what the sc.next method does when there are no more tokens.
Take a look at the documentation. The one you are using may not be the best choice for you.
Well, the Scanner Class has ways of telling us when there is nothing else to read.
Originally posted by ramya narayanan:
What is the pre-order and post-order he is saying.
What is the logic behind that?
Originally posted by ramya narayanan:
The reason I've found out is that it may throw java.util.NoSuchElementException when we use while(sc.hasNextLine()).
The reason being when I include some additional lines after last element in inputs.txt it will throw these exception.
Am I right Mark Vedder?
Originally posted by ramya narayanan:
No replies yet on what is pre-order or post-order?
Regards.
Joanne
Originally posted by ramya narayanan:
Mark, when I use the delimiter property of the Scanner class , it avoids the exception & I've tried it out with even, odd , one or no tokens.
No exception is thrown & it's working fine.
Input.txt:
output:
Change that line and run the program. Notice when you do that you are not getting one name per token. You are getting a full line as a token.
Why do you think that is?
Now remove or comment out the line that is setting the delimiter:
Notice the difference when that line is removed? Why did that happen?
We want to setup our code so we read the same thing (either a line or a token) and check if any more of that thing (a line or a token) exists.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Originally posted by ramya narayanan:
Any replies?
Originally posted by ramya narayanan:
Just for simple sorting i.e sorting on ascending order , if we put the elements in an array list & use collections.sort(arraylist,<comparator> ;) whether we can get the elements arranged in ascending order?
Even no need of using the comparator in collection.sort as the Strings are by default Comparable & naturally arranged in ascending order.
Is it possible?
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|