I'm working on program in java that will print unique sequence of number in array. I almost completed it but it sometimes generate the same sequences of numbers. If the sequence is the same i want program to print another sequence of number.
So here is what i have:
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Random;
public class Losowanie {
public static void main(String[] args)
{
Random r=new Random();
int miasta=6;
int pop=7;
int[][] ciag=new int[pop+1][miasta+1];
for(int i=1;i<=pop;i++){
for(int j=1;j<=miasta;j++){ciag[i][j]=r.nextInt(6)+1;}}
for(int i=1;i<=pop;i++)
{
for(int j=2;j<=miasta;j++)
{
for(int h=j-1;h>=0;h--)
{
if(ciag[i][j]==ciag[i][h]) {ciag[i][j]=r.nextInt(6)+1;h=j;}
}
}
}
for(int i=1;i<=pop;i++){
for(int j=1;j<=miasta;j++){System.out.print(" "+ciag[i][j]);}
System.out.print("\n");}
}
}
Aucun commentaire:
Enregistrer un commentaire