Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Beginner Coding problem in a class taught by professor with limited English comprehension

1. ## Beginner Coding problem in a class taught by professor with limited English comprehension

Hello, I have been taking a cs 2010 class and have finally gotten to start coding in Java. However, my professor cannot speak or write English very well so I am having to learn mostly by myself.
He recently sent us a project in which we have to:

1. Write a program that will use an array to store 10,000 randomly generated
numbers (ranging from 1 to 10,000 with no repeating numbers)

2. Using the selection sort algorithm to sort the number in ascending order, display the sorted sequence, each line showing just one number.

I have discovered that I will need to presumably generate the array with the 10,000 numbers, shuffle them, and then sort them.
However, I am completely lost on how to fill the array with the 10,000 numbers to begin with. I only know how to randomly fill them, but by doing that, I have repeating numbers.

Here is a snippet of what I have tried so far with no clue as to how to go from there. I thought I could write a while loop that would fill each one with (sum = 1+ sum), but I am not sure of the syntax or if that is even possible with arrays. Any help would be oh so helpful.

```package array.sorter.project;

import java.util.*;
import java.util.Arrays;

public class Sorting {
//generating 10000 spots in the array
public static void main(String args[]){
int[] tenthousand = new int[10000];

//loop to add 1 to x and set the new value of x to the array spot
int sum = 0;
while ( sum < 10000){
sum = sum + 1;
Arrays.fill(tenthousand, sum);
}

for (int i = 0; i < tenthousand.length; i++) {
int smallestNo = tenthousand[i];
int posWithSmallest = i;
for (int j = i+1; j < tenthousand.length; j++) {
int val = tenthousand[j];
if (val < smallestNo) {
smallestNo = val;
posWithSmallest = j;
}
}
int tmp = tenthousand[i];
tenthousand[i] = smallestNo;
tenthousand[posWithSmallest] = tmp;

}

for (int i = 0; i < tenthousand.length; i++) {
System.out.println("Position " + i + " : " + tenthousand[i]);
}

}

}```

I apologize in advance in any of this is terribly written or just completely wrong. As I said, I have no clue.

2. ## Re: Beginner Coding problem in a class taught by professor with limited English comprehension

I have discovered that I will need to presumably generate the array with the 10,000 numbers, shuffle them, and then sort them.
However, I am completely lost on how to fill the array with the 10,000 numbers to begin with. I only know how to randomly fill them, but by doing that, I have repeating numbers.
Are you sure the array is supposed to contain 10,000 numbers?

If so, and you didn't want any repeats, you wouldn't fill them with random numbers - you would fill them with the numbers 1->10,000 (that takes care of having no repeats) then shuffle them (that provides the randomness). What I'm thinking is that sorting the resulting array would be a bit pointless in this case as you know in advance what the result would be.

3. ## Re: Beginner Coding problem in a class taught by professor with limited English comprehension

I agree completely but that's exactly what the instructions say. I don't know. How does one go about filling the array with the numbers?

4. ## Re: Beginner Coding problem in a class taught by professor with limited English comprehension

How does one go about filling the array with the numbers?
You are making it too complicated with that while loop and the fill() thing. Use a for loop. In fact it will be a for loop that looks a lot like the one at the end that you use to print the contents of the array. Instead of printing each element you assign a value to each element:

```for (int i = 0; i < tenthousand.length; i++) {
tenthousand[i] = ...
}```

5. ## Re: Beginner Coding problem in a class taught by professor with limited English comprehension

Break the problem up and tackle and test each problem.

1. How do we generate a random number between 1 and 10,000?
2. Create an array to hold 10,000 numbers.
3. How do I store only unique values? Do I filter them before filling the array or after? What tools are there in the API to help me?
4. Look up the required "selection sort" algorithm and make sure I know how it works. Implement a sort method and test it.
etc..

6. ## Re: Beginner Coding problem in a class taught by professor with limited English comprehension

Originally Posted by tdat3
1. Write a program that will use an array to store 10,000 randomly generated
numbers (ranging from 1 to 10,000 with no repeating numbers)
If this is correct then your end sorted result is going to be an array with every value 1 to 10,000. Creating actual random numbers would take a long long time for this program to run. Perhaps this is what your prof wants, but IMO that's crazy. If i were to do this i would do it in a psuedo random way (if your prof argues, start the argument that nothing is truly random).

My Opinion:
write a for loop that will go through each number 1 through 10,000
use the random number generator to get your array space, if that space already has a value, increment until you find an open space and just put it there...random enough IMO

7. ## Supra Womens TK Society Shoes

The main levels of competition as asics workout shoes is Mizuno, what individuals as well as transfer a remarkable beach ball trainers. Normally, as with any athletic, there are many pertaining to alternate types which go unseen past a multitude of, never the less but the truth is bring forth a rather extreme super exceptional shoe many times which has a perfect sincerely worth. Do not concerned to try every hassle exclusive. For the world-wide-web in today's times, you're able to quite easily pass making use of the earn as well as a reveal reports along with dance shoes that almost all people have had. They've already pointless that will lie employing little well-rounded homework you can receive distinct views of these completely unique variations that you are studying.onal.
- - - - - - - - - - - - - - - - - -- - - -- - - -- - - - -- - -- - - - - - - - - -- - - - - - -- - -- - -
2012 new Supra TK Society Shoes,2012 supra sneakers
From:Mens Supra III Skytop Silver Black Shoes [supra1236] - \$89.33 : Cheap Supra Footwear Shoes on sale, Supra Shoes