Program with 200 random numbers?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 697 Views - Last Post: 09 May 2013 - 01:15 PM Rate Topic: -----

#16 GDSmith  Icon User is offline

  • New D.I.C Head

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

Re: Program with 200 random numbers?

Posted 09 May 2013 - 12:04 PM

View Posthansma, on 09 May 2013 - 11:35 AM, said:

How about this is this any better?
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
Was This Post Helpful? 1
  • +
  • -

#17 hansma  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • 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

Was This Post Helpful? -1
  • +
  • -

#18 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • 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?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2