public void readInput(Scanner sc) {
while (sc.hasNext())
{
//check if we are in a tag to begin with
String s = new String(sc.next());
if (Pattern.matches("[\\p{Punct}\\p{IsPunctuation}]", s.substring(
s.length() - 1)) && !Pattern.matches("[]", s.substring( s.length() - 1)))
//If word has punctuation at the end
{
Token ta = new Token(s.substring(0, s.length() - 1)); //Token of the word
Token tb = new Token(s.substring(s.length() - 1)); //Token of Punctuation
this.tokens.add(ta);
this.tokens.add(tb);
}
else //if no punctuation add whole word
{
Token t = new Token(s);
this.tokens.add(t);
}
if(s.compareTo("") == 0) {
double startTime = System.nanoTime();//
this.createWindows();
this.printTextBlock();
this.cleanup();
double endTime = System.nanoTime();
double duration = (endTime - startTime)/1000000000; //divide by 1000000 to
get
milliseconds.
System.out.println("\n\n" + duration + " seconds runtime");
}
}
sc.close();
答案 0 :(得分:0)
您需要通过将scanner对象传递给readInput方法来模拟用户输入
String input = "Input";
InputStream in = new ByteArrayInputStream(input.getBytes());
Scanner scanner = new Scanner(in);
readInput(scanner);