Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class WordScramble {
- static String words[][] = {{"EXPERIMENT", "PRESSURE", "ECLIPSE", "TEMPERATURE", "TELESCOPE", "INTERNET", "WINDOW", "RELEASE", "EXPRESSION", "REFLECT"}, {"INTELLIGENT", "MIGRATION", "ENVIRONMENT", "CONTINENT", "PLATINUM", "INTERNATIONAL", "RENOVATION", "ACCELERATION", "ABSTRACT", "CIVILIZATION"}, {"ASTEROID", "MICROSCOPE", "METAMORPHOSIS", "ELECTRONICS", "EFFORTLESSLY", "COMMANDER", "COORDINATION", "SOPHISTICATE", "UNRESTRICTED", "URBANIZATION"}};
- static int rounds = 0;
- public static void main(String s[]) {
- System.out.println(" Get ready to play Word Scramble. You will play 3 rounds - Easy, Medium and Hard. ");
- System.out.println("Enter anything to continue.");
- String x = new Scanner(System.in).nextLine();
- play();
- }
- static void play() {
- if (rounds == 3) {
- System.out.println("You have successfully won the game.");
- } else {
- String word = words[rounds][(int) (Math.random() * 10)];
- System.out.println("Round " + (rounds + 1) + ": " + scramble(word));
- System.out.println("You have only 1 chance to answer!");
- String y = new Scanner(System.in).nextLine();
- if (y.compareToIgnoreCase(word) == 0) {
- System.out.println(" Congratulations! You have given the correct answer: " + word);
- System.out.println("Enter anything to continue.");
- String z = new Scanner(System.in).nextLine();
- rounds++;
- play();
- } else {
- System.out.println(" You got the word wrong! The correct word was: " + word + ". You have lost the game.");
- }
- }
- }
- static String scramble(String x) {
- String y = "";
- while (x.compareTo("") != 0) {
- int n = x.length();
- String ch = "" + x.charAt((int) (Math.random() * n));
- y += ch;
- x = x.replaceFirst(ch, "");
- }
- return y;
- }
- }
Add Comment
Please, Sign In to add comment