# Program with 200 random numbers?

• (2 Pages)
• 1
• 2

## 17 Replies - 1102 Views - Last Post: 09 May 2013 - 01:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=320317&amp;s=9472fa78ca6af65bab6bebdc3b0ce176&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 GDSmith

Reputation: 1
• Posts: 2
• Joined: 09-May 13

## Re: Program with 200 random numbers?

Posted 09 May 2013 - 12:04 PM

hansma, on 09 May 2013 - 11:35 AM, said:

```class Test

{

public static void main(String[] args){

int[] array = createRandomArray(200);

Arrays.sort(array);

int searchValue = 24;

int value = Arrays.binarySearch(array, searchValue);

System.out.println(Arrays.toString(array));

System.out.println(value);
}
private static int[] createRandomArray(int value200){

int[] arr = new int[200];

for(int i=0; i < 1; i++){

}
return;
}
}

```

-Use the parameter that you have created for createRandomArray

```private static int[] createRandomArray(int value200){

int[] arr = new int[value200];
```

-Remember to make you for loop use the length of the array or else you will only fill the first index

```for(int i=0; i < arr.length; i++){

}
```

- Need a line of code assigning a value to each index of arr[] in the for loop(This is why you are getting 0's)

```arr[i] = YourCodeCreatingNumBetween1And1000;
```

- Remember to return a value of type int[] in method createRandomArray

```return arr;
```

-A negative number being returned for value means the searchValue was not found
-A positive number is the index of the array where the searchValue was fount

### #17 hansma

Reputation: -3
• Posts: 10
• Joined: 04-May 13

## Re: Program with 200 random numbers?

Posted 09 May 2013 - 12:42 PM

thanks for the help, but what do you mean when you say

```arr[i] = YourCodeCreatingNumBetween1And1000;
```

This post has been edited by macosxnerd101: 09 May 2013 - 01:54 PM
Reason for edit:: Removed quote

### #18 GregBrannon

• D.I.C Lover

Reputation: 2248
• Posts: 5,340
• Joined: 10-September 10

## Re: Program with 200 random numbers?

Posted 09 May 2013 - 01:15 PM

Don't quote the whole previous post when you have a question about one line. All that was needed was the last two lines. It's just bad form.

Without reading the whole thread, what I'd guess the poster meant was to assign to the element arr[i] a number between 1 and 1,000 generated by another method or statement. What don't you understand about that?