0% found this document useful (0 votes)
9 views2 pages

Bubble Sort Descending

The document is a Java program that implements the Bubble Sort algorithm to sort an array in descending order. It prompts the user to input the size of the array and its elements, then sorts the array using nested loops. Finally, it prints both the original and sorted arrays to the console.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Bubble Sort Descending

The document is a Java program that implements the Bubble Sort algorithm to sort an array in descending order. It prompts the user to input the size of the array and its elements, then sorts the array using nested loops. Finally, it prints both the original and sorted arrays to the console.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Bubble Sort Descending

import java.util.*; //Importing Packages

import java.io.*;

import java.lang.*;

public class Bubble_Sort_2 //declaring class

{ //opening braces of class

public static void main(String args[]) //declaring main method

{ //opening braces of main method

Scanner pa = new Scanner(System.in); //declaring Scanner class

System.out.println("Enter the size of the array");

int n = pa.nextInt(); //To Store the size of an Array

int a[] = new int [n]; //declaring an array of size n

int t=0; //temporary variable

System.out.println("Enter Number");

for(int i=0;i<n;i++) //Loop to input values in the Array

a[i] = pa.nextInt(); //To input values

System.out.println("ORIGINAL ARRAY");

for(int i=0;i<n;i++) //Loop to Print Array in Single Line

System.out.print(a[i]+"\t");

for(int i=0;i<n;i++) //Outer Loop of Bubble Sorting

for(int j=0;j<n-1;j++) //Inner Loop of Bubble Sorting

if(a[j] < a[j+1]) //To check if the value ahead is Bigger or not

t = a[j]; //To Inter-Change Values

a[j] = a[j+1];
a[j+1] = t;

System.out.println("\n"+"SORTED ARRAY");

for(int i=0;i<n;i++) //Loop to Print Sorted Array

System.out.print(a[i]+"\t");

} //closing braces of main method

} //closing braces of class

VARIABLE DATA TYPE FUNCTION


n Integer To Store the Size of an Array
a Integer To Store the Array
i Integer Used as a Local variable
t Integer Used to Transfer values
j Integer Used For the Bubble Sorting

You might also like