-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.java
More file actions
43 lines (36 loc) · 956 Bytes
/
Array.java
File metadata and controls
43 lines (36 loc) · 956 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
42
43
import java.util.*;
public class Array{
private static Scanner n = new Scanner(System.in);
private static Scanner s = new Scanner(System.in);
public static void main(String[] args){
System.out.println("Enter the number of elements in the array");
int N;
N = n.nextInt();
int [] Array = new int[N];
System.out.println("Enter the input");
for( int i = 0 ; i < N; i ++){
Array[i] = s.nextInt();
System.out.println("The " + i + " element is : " + Array[i]);
}
sort(N,Array);
display(N,Array);
}
public static int[] sort(int N, int[] Array){
int temp;
for (int i = 0; i <N; i++){
for(int j = i+1 ; j < N ; j++){
if (Array[i]> Array[j]){
temp = Array[i];
Array[i]= Array[j];
Array[j] = temp;
}
}
}
return Array;
}
public static void display(int N, int[] Array){
for (int i = 0; i <N; i++){
System.out.println(Array[i]);
}
}
}