#Word Shuffle Program Code Review & Help

1 messages · Page 1 of 1 (latest)

icy plinthBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hi there I have to create a program with these instructions: Write a program that selects a word and produces a “jumbled” version. For example, the letters of the word “TAKEN” might be scrambled as “AKNET”. Here are the specific rules for the game: The

the word "hello" could be rearranged to create the jumbled word "olhel".

Here is a sample code to achieve this:

import java.util.Random;

public class WordShuffle {
    public static void main(String[] args) {
        String word = "hello";
        String jumbledWord = shuffleWord(word);
        
        System.out.println("Original word: " + word);
        System.out.println("Jumbled word: " + jumbledWord);
    }
    
    private static String shuffleWord(String word) {
        Random random = new Random();
        char[] letters = word.toCharArray();
        
        for (int i = 0; i < letters.length; i++) {
            int randomIndex = random.nextInt(letters.length);
            
            // Swap letters at index i and randomIndex
            char temp = letters[i];
            letters[i] = letters[randomIndex];
            letters[randomIndex] = temp;
        }
        
        return new String(letters);
    }
}

In this code, the shuffleWord method takes a string as input, converts it into an array of characters, and then shuffles the characters randomly by swapping them at random indexes. The shuffled word is then returned as a string.

You can modify the word variable in the main method to test with different words. Let me know if you need any further clarification or help with this program!

visual summit
#

If you require to see any of the methods that I have created, let me know and I will send them : )

icy plinthBOT
#

Closed the thread.