• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using HashSet, but my code output is wrong when put into my homework grading system  RSS feed

 
Sammie Hassett
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code prints out correctly on my screen but when I go to submit it to my online homework grader it says that it is wrong. It looks like the order switches completly and I dont know how to have it not do that. It does not switch like that on eclipse, only when i go to submit the code. I know ordering is not preserved, but I am pretty sure I am supposed to use a set because of the eliminating duplicates.
My Code

and here is an image of what the grader is saying is wrong with my output:
Any help would be greatly appreciated
thank you
Screenshot-(102).png
[Thumbnail for Screenshot-(102).png]
Result
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using a HashSet which has an iterator that returns elements in no particular order. It looks like the test is looking for elements in ascending order. The iterator of a TreeSet goes over the elements of the set in ascending order.
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch!
 
Sammie Hassett
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!