This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Create string in random order. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Create string in random order." Watch "Create string in random order." New topic

Create string in random order.

Shirley Flood

Joined: Mar 25, 2008
Posts: 4
String text = "Work at Home";
I need to write the code that will create a new string the same length, and contain each character of the original string in random order.

class Stringrandom {

public static void main(String[] arguments) {
String str = "Work at Home";
System.out.println("The random string is: " + str.random());

[ March 27, 2008: Message edited by: Shirley Flood ]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11858

First, welcome to the Ranch!!!

Second, we're happy to help. But you need to show us what you've done, and tell us where you're stuck. We can point you in a direction, but you're gonna have to do most of the work yourself.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor

Joined: Oct 27, 2005
Posts: 20078

Pesudo code:

Now for some hints:
- use StringBuilder (Java 5 or up) or StringBuffer (Java 1.4 and down) for random and orig
- use java.util.Random for getting the random index

How To Ask Questions How To Answer Questions
Have you checked out Aspose?
subject: Create string in random order.
It's not a secret anymore!