aspose file tools
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 11563

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: 19844

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
Don't get me started about those stupid light bulbs.
subject: Create string in random order.