So This program is supposed to shuffle a three world letter with an array so it displays the 3 possible letter combos. We are using the word cat. It doesn’t work. Help please?
import java.util.Scanner;
public class Unscramble{
public static void main(Stringargs){
System.out.println(“\f”);
Scanner input = new Scanner(System.in);
String word;
char letters;
char placeholder = new char[1];
//Obtain word to scramble
System.out.print("Enter a word to scramble: ");
word = input.nextLine();
letters = word.toCharArray();
//Scramble word
for(int i = 0; i <= word.length(); i++){
for(int j = 0; j <= word.length() - 1; j++){
System.out.print(letters[j]);
if(j == 2 && word.length() == 2){
System.out.println(letters[0]);
}else if(j == 3 && word.length() == 3){
System.out.println(letters[0]);
}
}
System.out.println();
placeholder[0] = letters[0];
if(word.length() == 2){
letters[0] = letters[1];
letters[1] = letters[2];
letters[2] = placeholder[0];
}else if(word.length() == 3){
letters[0] = letters[1];
letters[1] = letters[2];
letters[2] = letters[3];
letters[3] = placeholder[0];
}
}
//cat;
//tac;
//act;
//cta;
//tca;
//atc
}
}