So I'm supposed to make a "scramble" game that asks the user for a word, then the program scrambles that word for the second user to guess.
import java.util.*;
class scrabble {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter a word: ");
String abc = input.nextLine();
String scrambled = "";
Random randGen = new Random();
while(scrambled.length() != abc.length())
{
char rand = abc.charAt(randGen.nextInt(abc.length()));
if(!scrambled.contains("" + rand))
scrambled += rand;
}
System.out.println(scrambled);
}
}
Output: Enter a word: computer emotucrp
But if I enter the word "continue", the program goes into an infinite loop.