-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillAndSortArray2.java
More file actions
41 lines (32 loc) · 871 Bytes
/
Copy pathFillAndSortArray2.java
File metadata and controls
41 lines (32 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* This program prompts a user to enter a number of elements in an array and sorts the array
* in a list and prints the elements.
*
* @author {user}
* Course: COMP B11
* Created: Mar 19, 2018
* Source File: FillAndSortArrays.java
*/
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class FillAndSortArray2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random random = new Random(1234);
int element;
System.out.println("How many elements are in the array? ");
element = in.nextInt();
double[] array = new double[element];
for (int i = 0; i < array.length; i++)
{
array[i] = random.nextDouble() * 100;
}
Arrays.sort(array);
for (double elements : array)
{
System.out.println(elements);
}
in.close();
}
}