-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingArray.java
More file actions
42 lines (38 loc) · 953 Bytes
/
SortingArray.java
File metadata and controls
42 lines (38 loc) · 953 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
//Program that copies contents of one array to another using length member.
import java.util.Scanner;
public class SortingArray
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of Array :- ");
int size = sc.nextInt();
int[] array = new int[size];
System.out.print("\nEnter the Array - ");
for(int i=0; i<size; i++)
{
System.out.print("\nEnter the " +(i+1)+" element - ");
array[i]=sc.nextInt();
}
System.out.print("\nEnterd Array is -- ");
for(int i=0; i<size; i++)
{
System.out.print("\t"+array[i]);
}
int temp;
for(int i=0; i<size; i++)
{
while(array[i] >= array[(i+1)])
{
temp = array[i];
array[i] = array[(i+1)];
array[(i+1)] = temp;
}
}
System.out.print("\nArray in the Sorted order is :- ");
for(int i=0; i<size; i++)
{
System.out.print("\t"+array[i]);
}
}
}