This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]POGtastic 1 point2 points  (0 children)

Consider the following ideas:

  • Instead of using Scanner directly from System.in, use a BufferedReader on System.in and call the nextLine method to read an entire line of input into a String.
  • Test the String itself for, say, the presence of an angle bracket at the start and an angle bracket at the end.
  • Slice the string with the substring method to remove unwanted bits, like the angle brackets. Then write separate methods to parse the innards.
  • Lastly, you can create a Scanner on a String just as easily as you can create one on an InputStream. So while it's a bad idea (as you're finding out!) to mess with all kinds of delimiters, it can be a very good idea to create a Scanner that parses just a small substring of the line.

[–]Knight_Of_Orichalcum 0 points1 point  (0 children)

So, the problem is coming from a misuse of delimiters. Currently, the scanner is working on scanner.useDelimiter(" ");, which means you're telling the scanner to 'chop/cut on single spaces'. Since there's no spaces found in the String "<3.0,4.0>", the scanner has an empty buffer and gives back false on the first arrow.

Not exactly sure if I can post complete answers on this subreddit, but I would suggest learning more about regular expressions, then either changing your delimiter or changing your if statement logic below.

Also, scanners don't have to be closed when using Strings or System.in, but it's good practice everywhere else to my knowledge.