write a program to input 15 integer elements in an array and sorr them in descending order using the bubble sort technique
Answers
Answered by
2
import java.io.*;
import java.util’*;
class AscendingOrder
{
public static void main(String args[])
{
int i, j, temp;
Scanner sc = new Scanner(System.in);
int arr[] = new int[15];
System.out.println(“Enter 15 integers:”);
for (i = 0; i < = 15; i+ +) { arr[i] = sc.nextlntO;
for(i = 0; i < 14; i++){ for(j = 0; j < 14 -i; j + +){
if(arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr [j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println(“Elements in ascending order are::”);
for (i = 0; i < 15; i+ +) { System.out.println(arr[i]);
}
}
}
}
Similar questions