Scramble words Download

Christina Cacioppo

strings, for loops, functions Student approved


Scrambling words is a longstanding hobby of computer scientists. (When you work with text all the time, you've got to entertain yourself somehow, I guess.)

Let's scramble a few words ourselves.


Write a method scrambleWord that takes in a word and returns a String that contains a scrambled version of the word, according to these rules:

  1. Scramble each letter of the word, starting with the first
  2. If the word contains "A[letter]", swap the two characters to become "[letter]A"
  3. Swap each letter only once

Starter code

class Scramble{

	/* Returns a scrambled version of the word it's passed
	 * @ param 	word – the word to be scrambled
	String scrambleWord(String word){
		// Start scrambling!

Expected output

Depends the word that's passed, but here's a few examples:


One solution


Useful tools to solve the problem