Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Help :O

Name: ipoopmypants !49.zlWoq9M 2009-11-24 22:53

Anyone know how in Java I check check an array to see if there are any duplicates?

        int[] random = new int[100];
        Random randomGenerator = new Random();
        boolean inArray = true;

for(int i = 0; i < random.length; i++)
        {
            random[i] = randomGenerator.nextInt(999);
            if(random[i] == /*CHECK ALL OTHER INDEXES IN THE ARRAY*/)
            {
                random[i]++;
            }
           
            }

Name: Anonymous 2009-11-25 1:38

import java.util.Random;
import java.text.DecimalFormat;
public class Random100 {
    public static void main(String[] args) {
        boolean[] random = new boolean[1000];
        Random rng = new Random();
        int n;
        for(int i = 0; i < 100; i++) {
            while(random[(n = rng.nextInt(1000))]);
            random[n] = true;
            System.out.print(new DecimalFormat("000").format(n)+((i%10==9)?"\n":" "));
        }
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List