L
Louie LaRue
This is a program that randomizies the strings in the array 20 times
and outputs them in a single line. How do I make it output 12 strings
per line?
thanks, Lane
/*
* Main.java
*
* Created on October 29, 2006, 12:27 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package randomizing;
/**
*
* @author mltodd
*/
import java.util.Random;
public class Main {
public static void main(String [] args) {for (int lap=1; lap <=20;
lap++) {
String [] input = {"ais ", "b ", "bes ", "bis ", "c' ", "ces' ",
"cis' ",
"d' ", "des' ", "dis' ", "e' ", "ees' ", "eis'
", "f' ", "fes' ",
"fis' ", "g' ", "ges' ", "gis' ", "a' ", "aes'
", "ais' ", "b' ",
"bes' ", "bis' ", "c'' ", "ces'' ", "cis''",
"d'' ", "des'' ",
"dis'' ", "e'' ", "ees'' ", "eis'' ", "f'' ",
"fes'' ", "fis'' ",
"g'' ", "ges'' ", "gis'' ", "a'' ", "aes'' ",
"ais'' ", "b'' ",
"bes'' ", "bis'' ", "c''' ", "ces''' ", "cis'''
", "d''' ",
"des''' ", "dis''' ", "ees''' "} ;
String [] result = randomSortArray(input);
for (int i=0; i<result.length; i++)
System.out.print (result);
}
}
public static String [] randomSortArray(String [] input) {
int size = input.length;
int [] indices = new int[size];
for (int i=0; i<size; i++)
indices = i;
Random random = new Random();
for (int i=0; i<size; i++) {
boolean unique = false;
int randomNo = 0;
while (!unique) {
unique = true;
randomNo = random.nextInt(size);
for (int j=0; j<i; j++) {
if (indices[j] == randomNo) {
unique = false;
break;
}
}
}
indices = randomNo;
}
String [] result = new String [size];
for (int i=0; i<size; i++)
result[indices] = input;
return result;
}
}
and outputs them in a single line. How do I make it output 12 strings
per line?
thanks, Lane
/*
* Main.java
*
* Created on October 29, 2006, 12:27 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package randomizing;
/**
*
* @author mltodd
*/
import java.util.Random;
public class Main {
public static void main(String [] args) {for (int lap=1; lap <=20;
lap++) {
String [] input = {"ais ", "b ", "bes ", "bis ", "c' ", "ces' ",
"cis' ",
"d' ", "des' ", "dis' ", "e' ", "ees' ", "eis'
", "f' ", "fes' ",
"fis' ", "g' ", "ges' ", "gis' ", "a' ", "aes'
", "ais' ", "b' ",
"bes' ", "bis' ", "c'' ", "ces'' ", "cis''",
"d'' ", "des'' ",
"dis'' ", "e'' ", "ees'' ", "eis'' ", "f'' ",
"fes'' ", "fis'' ",
"g'' ", "ges'' ", "gis'' ", "a'' ", "aes'' ",
"ais'' ", "b'' ",
"bes'' ", "bis'' ", "c''' ", "ces''' ", "cis'''
", "d''' ",
"des''' ", "dis''' ", "ees''' "} ;
String [] result = randomSortArray(input);
for (int i=0; i<result.length; i++)
System.out.print (result);
}
}
public static String [] randomSortArray(String [] input) {
int size = input.length;
int [] indices = new int[size];
for (int i=0; i<size; i++)
indices = i;
Random random = new Random();
for (int i=0; i<size; i++) {
boolean unique = false;
int randomNo = 0;
while (!unique) {
unique = true;
randomNo = random.nextInt(size);
for (int j=0; j<i; j++) {
if (indices[j] == randomNo) {
unique = false;
break;
}
}
}
indices = randomNo;
}
String [] result = new String [size];
for (int i=0; i<size; i++)
result[indices] = input;
return result;
}
}