Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashSet;
- import java.util.Scanner;
- import java.util.Random;
- import java.util.ArrayList;
- import java.util.HashSet;
- /**
- * InputReader class to be used for read input entry.
- *
- * @author Muhammad Naufaldillah
- * @version 16 November 2020
- */
- public class InputReader
- {
- private Scanner reader;
- public InputReader()
- {
- reader = new Scanner(System.in);
- }
- /**
- * Read a line of text from standard input (the text
- * terminal). and return it as set of words.
- *
- * @return A set of Strings, where each String is one of the
- * words typed by the user
- */
- public HashSet<String> getInput()
- {
- System.out.print("> "); // print prompt
- String inputLine = reader.nextLine().trim().toLowerCase();
- String[] wordArray = inputLine.split(" ");
- // add words from array into hashset
- HashSet<String> words = new HashSet<String>();
- for (String word : wordArray)
- {
- words.add(word);
- }
- return words;
- }
- }
Add Comment
Please, Sign In to add comment