Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Non-sequential shuffle help

Thread Tools

Non-sequential shuffle help

Smartfood Smartfood is offline
Junior Member
Join Date: Oct 2008
Posts: 1
I'm having a bit of difficulty. I'm trying to make a program that takes a command line argument and then shuffles it then prints the shuffled numbers. However, the numbers cannot follow in oder. Ie: 2 cannot follow 3, 6 cannot follow 5, etc.

Here is my code:
	int numSongs = Integer.parseInt(args[0]);

	int[] song = new int[numbSongs];
	for (int position = 0; position < numbSongs; position++) {
	    int list = position;
	    song[position] = list;
   	for (int current = 0; current < numbSongs; current++) {
	    int swap = current + (int) (Math.random() * (numbSongs - current));
	    int tempSong = song[current];
	    song[current] = song[swap];
	    song[swap] = tempSong;
	    if (song[current] == song[swap+1] || song[current] == song[swap-1])
		{ HELP!  }
		{ System.out.println(song[swap]); }
	System.out.println(song[current] + " ");
My problem, I do not know what to put in where it says "HELP" in bold, red letters. I've tried numerous things! Each time, to no avail. Please help!
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array.shuffle/Array.shuffle! Jeff Moore Ruby 6 10-09-2008 07:14 PM
Ipod shuffle help please Paul Burdett Computer Support 2 08-14-2005 10:01 PM
iPod Shuffle + Windows XP Limited User Account Goonerak Computer Support 0 06-12-2005 01:16 PM
Shuffle an array of integers. Java 12 04-26-2005 05:31 AM
shuffle stickems Computer Support 1 07-27-2003 07:04 PM