-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.java
More file actions
42 lines (32 loc) · 995 Bytes
/
Q3.java
File metadata and controls
42 lines (32 loc) · 995 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
import java.util.Scanner;
class Q3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size;
System.out.println("Enter Size: ");
size = sc.nextInt();
int arr[] = new int[size];
for (var i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
System.out.println("Sorted Array:");
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++)
{
for(int j=1; j < (n-i); j++)
{
if(arr[j-1] > arr[j])
{
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
}
for (var i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
sc.close();
}
}