...
Create a new IntelliJ project.
Create a new Java class that will contain the
main
method.Within the
main
method, create an array of ten elements of typeint
.Use the class method
Math.random()
to fill the array with random values. Note thatMath.random()
returns a value between 0.0 and 1.0, so you may need to multiply this number by some factor (i.e. 100) and cast the result to anint
. (Hint: use loop to fill up the array)Print out the content of your array - again use a loop. You should see 10 random numbers ranging from 0 to 99.
Try to sort your array. As you may know, there are a number of different sorting algorithms that we could use. While it is not very efficient with large arrays, the simplest one to understand is called the bubble sort. The bubble sort gets its name from the way large values tend to move towards the top of the array as multiple passes are made though the array. The number of passes required is equal to the number of elements in the array minus one. To implement the bubble-sort algorithm requires two nested loops. Basically, you need to compare each element in the array with those above it. If the value of the element is greater than any of them, it must be swapped with the lesser one.
...