Question
Write a program to input 10 integer elements in an array and sort them
In descending order using bubble sort technique.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class program7
{
public static void main(String[] args)
{
int i=0,j=0,temp=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter ten numbers:");
int[] numbers = new int[10];
for (i = 0; i < 10; i++)
{
numbers[i] = sc.nextInt();
}
for (i = 0; i < 10-1; i++)
{
for (j = 0; j < 10 - i - 1; j++)
{
if (numbers[j] < numbers[j + 1])
{
temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
System.out.println("Sorted Numbers:");
for (i = 0; i < 10; i++)
{
System.out.print(numbers[i]+" ");
}
}
}