Welcome to Dream.In.Code
Become a Java Expert!

Join 149,478 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,624 people online right now. Registration is fast and FREE... Join Now!




Recursive search method

 
Reply to this topicStart new topic

Recursive search method

Lady Athena
25 Apr, 2007 - 05:53 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2007
Posts: 25


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Recursive Search Method
25 Apr, 2007 - 06:38 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,302



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Recursion involves creating a function that calls itself, until a base case has been reached.

Check out the following link to get a basic understanding of how recursion works.
http://danzig.jct.ac.il/java_class/recursion.html

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month