Guest User

Untitled

a guest
May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import static java.lang.System.out;
  2.  
  3. import java.util.ArrayList;
  4. import java.io.IOException;
  5.  
  6. public class lessugly99bitches {
  7.     public static void main(String[] args) {
  8.         String word = "attrst", var;
  9.         ArrayList<String> old = new ArrayList<String>(), word2 = new ArrayList<String>();
  10.         out.println(String.format("? för att få hjälp\n! för att avsluta\n\nJag tänker på ett ord: %s", new String(new char[word.length()]).replaceAll("\0","* ")));
  11.         while (true) {
  12.             out.print("> ");
  13.             try {var = ""+(char)System.in.read();}
  14.             catch (IOException e) {break;}
  15.             if (var.equals("!")) break;
  16.             out.print((var.equals("?")?"Läs koden för hjälp (! quittar)\n":""));
  17.             if (!var.matches("[a-z]") || old.contains(var)) continue;
  18.             old.add(var);
  19.             for (char w: word.toCharArray()) word2.add((old.contains(w+"")?w+"":"*"));
  20.             out.println((word.contains(var)?"Rätt":"Fel") + ": " + word2.toString().replaceAll("[^a-z*]",""));
  21.             out.println("Gissat: " + old.toString().replaceAll("[^a-z]",""));
  22.             if (word2.toString().replaceAll("[^a-z*]","").equals(word)) {
  23.                 out.println("Du vann!!!!");
  24.                 break;
  25.             }
  26.             word2.clear();
  27.         }
  28.     }
  29. }
Add Comment
Please, Sign In to add comment