Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I an trying to get this by tonight. There is something wrong with the solution I began to come up with. Can you inform me
I an trying to get this by tonight. There is something wrong with the solution I began to come up with. Can you inform me what is going on?
Step 1: Input. You will prompt the user to enter a word to be scrambled Step 2: Calculation. Write a method private static String Scramble (String word) that constructs a scrambled version of a given word, randomly flipping two characters other than the first and last one. Helpful hints We can use the substring method to help us change the value of a character in a string. For example, let's say we want to change the 5th character (ie, the character at index 4) of myName to the character String myName "aymond" myName myName. Substring(0,41+'x' + myName. Substring(5); Step 3: Output. The program will print out the scrambled version of the word provided by the user, and then prompt the user to enter another word. If the user is finished, they can indicate that they are ready to stop the program. If the user wants to continue entering words to scramble, the program should loop back to Step 1. Example program run Enter a word to scramble: pickle Scrambled word: pkcile Would you like to enter another word to scramble? (Y/N) Invalid response: y Would you like to enter another word to scramble? (Y/N) Enter a word to scramble: Scrambled word: a Would you like to enter another word to scramble? (Y/N) do Invalid response: do Would you like to enter another word to scramble? (Y/N) Enter a word to scramble: dog Scrambled word: dog Would you like to enter another word to scramble? (Y/N) Enter a word to scramble: dogs Scrambled word: dgos Would you like to enter another word to scramble? (Y/N) Enter a word to scramble: 1import java.util.Random: 5esc ramb 14] 15 public class Scramble 16 static Scanner innew Scanner(System.in): 1/.in 17 18e 19 20 21 public static void main(String[] args) Fl System.out.printLn("Enter a word:"): //user input String scrambledword-in.next); //product String result-""; //result 23 24 25 if (scrambledword.lengthO >2) //proper amount of characters 326 result-result scrambledWora.substring.Q.1) scrambleLscranbledrd.) + scrambledWord . substring (MRrd. length ()-1); 27 28 29 30 31 32 else result result+ scrambledword; System.out.println(result); 34 35 36e private static void scramble(String scrambledword) i // TODO Auto-generated method stubl 38 41Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started