Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this code must be able to take a word of any length and jumble it code : import java.util.*; public class WK2 { public static

this code must be able to take a word of any length and jumble it
code :
import java.util.*;
public class WK2 {
public static String createJumble(String word){
for (int i=0; i
//adding the "" to convert the char into a string
//this is a shortcut for converting charumbers to string
wordList.add(word.charAt(i)+ "");
}
//this should print an ArrayList [J,a,v,a]
System.out.println(wordList);
//Now create a new string where you jumble the word Java
//A sample jumble: aJav
//the following generates a random number between 0-3
//you may need to use it in your code somewhere
//randomNum = (int)(Math.random()*4);
int randomNum = 0;
String jumble="";
//Your code goes here
//Create a for loop that loops 4 times
//In the loop, create a random number
//Using the random number, get a letter from wordList
//Add the chosen letter to a string
//Remove this letter from the wordList
//(Think: What should be the range from which the random /umber is chosen? Remember you are removing items from //the wordList as the loop progresses.)
return jumble;/**What happens when this line is removed? Why?**/
}
public static void main(String[] args) {
/**should wordList be declared here since this is local to this method? Where should you place this line of code? **/
ArrayList wordList = new ArrayList();
String w = "Java";
/**how many arguments/inputs does createJumble take?
How many are here? If they mismatch, which one should you
remove from here?**/
String result = createJumble(w, w.length());
}
}
image text in transcribed
image text in transcribed
The following program converts a given string into an ArrayList. For example, the string "java" is converted into the ArrayList["", "a", "V", "a"). Your task is to create another string from this ArrayList where the word Java is jumbled. Remember, an ArrayList size changes as you add/remove items from it. I have provided algorithmic guideline for the code There are some errors in the code that you have to fix-only the bolded code needs to be changed or moved. No need to change anything else. Optional: Change this program so that it accepts user input (single word of any length) and jumbles it. import java.util. public class WK2 public static String createJumble (String word) for (int i=0; i wordList = new ArrayList(); String w- "Java": /**how many arguments/inputs does createJumble take? How many are here? If they mismatch, which one should you remove from here?**/ String result - createJumble (w, w.length())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

Please make it fast 6 4 1 .

Answered: 1 week ago

Question

=+j on to staff their operations in the global marketplace.

Answered: 1 week ago