I've been staring at this problem for some time and need some help on how to go about this lab. I have to add a recursive search to the following code answering how many times the given value occurs in the array.
CODE
import java.util.*;
import java.lang.Math;
import java.util.Arrays;
public class RandomNumbers
{
public static void main(String[] args) {
int[] x= new int[1000];
int count;
int temp;
int index;
int y=0;
int data=0;
for (count = 0; count < 1000; count ++)
{
x[count] = (int)(Math.random() * 10001);
}
for(count=0; (count<x.length-1); count=count+1)
{
for(index=0;(index<(x.length-count-1)); index=index+1)
{
if(x[index]> x[index+1])
{
temp=x[index];
x[index]=x[index+1];
x[index+1]=temp;
}
else {}
}
}
for (count=0; count<=10000; count=count+1)
{
for (index=0; index<1000; index=index+1)
{
if (x[index]==count)
{
data=data+1;
}
else{}
}
if(data>0)
{
y=y+1;
}
else{}
data=0;
}
System.out.println("\n\nThere are"+y+"unique values");
}
}
Please help? .__.
This post has been edited by Lady Athena: 25 Apr, 2007 - 06:06 PM