-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathbubblesort.java
More file actions
35 lines (34 loc) · 877 Bytes
/
bubblesort.java
File metadata and controls
35 lines (34 loc) · 877 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
package com.kraken;
import java.util.*;
public class bubblesort {
public static void sort(int arr[])
{
for(int i = 0; i<arr.length -1; i++)
{
for(int j=0; j<arr.length -i -1; j++)
{
if(arr[j] < arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
int len = arr.length;
for(int i = len -1; i>=0; i--)
{
System.out.print(arr[i]+" ");
}
}
public static void main(String args [])
{
Scanner sc = new Scanner(System.in);
int arr [] = new int [5];
for(int i = 0; i<arr.length; i++)
{
arr[i] = sc.nextInt();
}
sort(arr);
}
}