Class 10th ICSE

Q.7

Write a java program to declare an array of double datatype of 20 elements and sort them in ascending order using bubble sort technique.

Solution :- 

import java.util.*;
class p7{
public static void main(){
Scanner sc =new Scanner(System.in);
int i,j,temp;
int a[]=new int[20];
for(i=0;i<20;i++){
System.out.println(“Enter number”);
a[i]=sc.nextInt();
}
for(i=0;i<20-1;i++){
for(j=0;j<20-i-1;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println(“Sorted array is as follows”);
for(i=0;i<20;i++){
System.out.println(a[i]);
}
}
}

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable

Popular Videos

Play Video

UX for Teams

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer

Play Video

SEO & Instagram

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer