Question
Write a program to input 15 integer elements in an array and sort them in ascending order using the 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 program6
{
public static void main(String[]args)
{
int i=0,len=0,temp=0,j=0;
Scanner sc = new Scanner(System.in);
int arr []=new int[15];
System.out.println("Enter 15 elements in an array ");
for(i=0;i<15;i++)
{
arr[i]=sc.nextInt();
}
len=arr.length;
for(i=0;i< len-1;i++)
{
for(j=0;j< len-1-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(i=0;i< len;i++)
{
System.out.print(arr[i]+" ");
}
}
}
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale