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

Java Practical 3

The document provides a Java program that implements the Bubble Sort algorithm to sort a list of integers input by the user. It prompts the user to enter the number of integers and then the integers themselves, before sorting and displaying the sorted list. The code includes necessary imports, user input handling, and the sorting logic using nested loops.

Uploaded by

hahipe8343
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)
2 views2 pages

Java Practical 3

The document provides a Java program that implements the Bubble Sort algorithm to sort a list of integers input by the user. It prompts the user to enter the number of integers and then the integers themselves, before sorting and displaying the sorted list. The code includes necessary imports, user input handling, and the sorting logic using nested loops.

Uploaded by

hahipe8343
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

Practical 3

Q3. Design, Develop, and Implement a Program in Java for sorting an


element from data given by the user, using Bubble Sort.
Code:- import [Link];

class bubblesort{
public static void main(String[] args) {
int num,i,j,temp;
Scanner input = new Scanner([Link]);

[Link]("Enter the number of integers to sort:");


num = [Link]();
int array[] = new int[num];

[Link]("Enter"+ num+ "integers:");

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


array[i] = [Link]();

for(i=0; i< (num - 1);i++){


for (j = 0; j<num-i-1; j++){
if (array [j]>array [j+1])
{
temp= array [i];
array[j] = array[j+1];
array[j+1]=temp;
}
}
}
[Link]("Sorted list of integers:");
for (i=0; i<num;i++)
[Link](array [i]);
}
}

Output:-

You might also like