fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6. class Ideone {
  7. public static void main(String[] args) throws java.lang.Exception {
  8. Set < String > uniqueKeywords = new HashSet < String > ();
  9. final String regex = "<adjective>|<plural-noun>|<place>|<noun>|<funny-noise>|<person's-name>|<job>|<CITY>|<Color!>|<Exciting-adjective>|<Interersting-Adjective>|<aDvErB>|<NUMBER>|<Plural-noun>|<body-part>|<verb>|<Number>|<verB>|<job-title>";
  10. final String filecontent = "Text template containing all sorts of .. <adjective>, <plural-noun>, <place>, <noun>, <funny-noise>, <person's-name>, <job>, <CITY>, , <Color!> <Exciting-adjective>, <Interersting-Adjective>, <aDvErB>, <NUMBER>, <Plural-noun>, <body-part>, <verb>, <Number>, <verB>, <job-title>, String data1 = sc.nextLine(); blah blah";
  11.  
  12. final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
  13. final Matcher matcher = pattern.matcher(filecontent);
  14.  
  15. while (matcher.find()) {
  16. uniqueKeywords.add(matcher.group(0));
  17. }
  18.  
  19. Scanner user_input = new Scanner(System.in);
  20. for (String keyword: uniqueKeywords) {
  21. System.out.println("Enter a " + keyword);
  22. String replacement = user_input.next();
  23. String replacedData1 = filecontent.replace(keyword, replacement);
  24. System.out.println(replacedData1);
  25. }
  26. }
  27. }
Runtime error #stdin #stdout #stderr 0.12s 29484KB
stdin
Standard input is empty
stdout
Enter a <funny-noise>
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1371)
	at Ideone.main(Main.java:22)