0% found this document useful (0 votes)
4 views3 pages

Program 1

Uploaded by

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

Program 1

Uploaded by

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

PROGRAM 1 :

A class BubSort has been

import java.util.*;

class BubSort

int a[],n;

BubSort(int nn)

n=nn;

a=new int[n];

void input()

Scanner sc=new Scanner(System.in);

int i;

System.out.println("enter "+ n +" numbers");

for(i=0;i<n;i++)

a[i]=sc.nextInt();

void sort()

int i,j,t;

for(i=0;i<n-1;i++)

for(j=0;j<n-1-i;j++)

{
if(a[j]>a[j+1])

t=a[j];

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

a[j+1]=t;

void display()

int i;

System.out.println("sorted array");

for(i=0;i<n;i++)

System.out.println(a[i]);

public static void main()

Scanner sc=new Scanner(System.in);

int p;

System.out.println("enter size of array");

p=sc.nextInt();

BubSort ob=new BubSort(p);

ob.input();

ob.sort();

ob.display();

You might also like