help with arrays

making random numbers into an array, sorting

Page 1 of 1

10 Replies - 2078 Views - Last Post: 05 October 2010 - 01:38 AM Rate Topic: -----

#1 programming_noob   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-September 10

help with arrays

Posted 04 October 2010 - 11:48 PM

So as you may have guessed I am a relatively new programmer, and I need a way to get the random numbers I have into an array so I can sort them. I have a random number generator and I know how to make a quick sort but I need to fit the numbers into an array, or do I? I don't know I just need help. Here is the simple random number generator I have made.

import java.util.*;



public class NumberGenerator {
	public static void main(String args[]){
	Random Generator = new Random();
	
	
		for (int idx = 1; idx <=10000; ++idx ){
		int nums = Generator.nextInt(10000);
		System.out.println(nums);
		
		
		{
		
		}
		}
}

}



Is This A Good Question/Topic? 0
  • +

Replies To: help with arrays

#2 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: help with arrays

Posted 04 October 2010 - 11:51 PM

uhm, "array[index] = whatever", maybe?
Was This Post Helpful? 0
  • +
  • -

#3 programming_noob   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-September 10

Re: help with arrays

Posted 05 October 2010 - 12:01 AM

like how?
Was This Post Helpful? 0
  • +
  • -

#4 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: help with arrays

Posted 05 October 2010 - 12:06 AM

String[] array = new String[5];
for (int index = 0; i < array.length; i++) {
    array[index] = String.valueOf(index);
}

Was This Post Helpful? 0
  • +
  • -

#5 Dean_Grobler   User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Re: help with arrays

Posted 05 October 2010 - 12:06 AM

Expanding a bit on Masijades reply:

int[] myArray = new int[1000];

for(int idx = 0;idx <=1000; ++idx){
	int nums = Generator.nextInt(1000);
	System.out.println(nums);
	myArray[idx] = nums;
}



*Aww crap! Too late.. hate it when that happens...

This post has been edited by Dean_Grobler: 05 October 2010 - 12:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: help with arrays

Posted 05 October 2010 - 12:10 AM

Sorry, but I downrepped that post as that is not helping, IMHO, that is doing it for him. I admit my first reply was sarcastic and you can downrep it if you please, but it was aimed at making the OP think. As was the second post since it showed how to work with arrays (assigning values to them) but did not give him a cut-n-paste answer. Once again, making him think. No one learns anything with a cut-n-paste answer.
Was This Post Helpful? 0
  • +
  • -

#7 programming_noob   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-September 10

Re: help with arrays

Posted 05 October 2010 - 12:20 AM

@masijade, that's ok I realize my question was very basic and I don't mind your sarcasm because of that. Thanks for the replies.
Was This Post Helpful? 0
  • +
  • -

#8 Dean_Grobler   User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Re: help with arrays

Posted 05 October 2010 - 12:24 AM

Hmm, okay that's understandable I guess. Sometimes just looking at code you can learn alot more that little hints(that's how I learn). But whatever blows your hair back I suppose.

This whole "point system" thing is a little childish though don't you think?
Was This Post Helpful? 2
  • +
  • -

#9 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: help with arrays

Posted 05 October 2010 - 12:29 AM

View PostDean_Grobler, on 05 October 2010 - 07:24 AM, said:

Hmm, okay that's understandable I guess. Sometimes just looking at code you can learn alot more that little hints(that's how I learn).

Yes, you can. When you are the searching for examples of specific things since those examples, are, usually, not custom tailored to your purpose and so, usually, are not simply cut-n-paste solutions. So, you actually have to read and understand at least a modicum of that code. When, however, you go to a forum and so "do this or that" and some one gives you a custom-tailored cut-n-paste solution, then, 99% of the time it will not even be looked at and just cut-n-pasted in and everythings good. Thereby having learned nothing.
Was This Post Helpful? 1
  • +
  • -

#10 Dean_Grobler   User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Re: help with arrays

Posted 05 October 2010 - 12:38 AM

You are also right, you get the guys that WANT to learn, so even if you just give them the cut-and-pasta code. They will look into it and try and understand it and learn from it.

Then you get they people that would just cut-and-paste it without even having a look at it (the lazy losers).But at the end of they day, they just screwing themselves over. So, all in all, it's his choice if he wants to benefit from it or not.

Not up to us to "try and teach" someone that doesn't want to learn. :smartass:

No hard feelings...
Was This Post Helpful? 0
  • +
  • -

#11 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: help with arrays

Posted 05 October 2010 - 01:38 AM

Doesn't mean that we should facilitate the "non-learners" though.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1