ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2019 ICSE Computer Science Paper



Share with a Friend

Solved 2019 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Sort Array Elements in Ascending Order using the Bubble Sort Technique Program - ICSE 2019 Computer Science

Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.

import java.util.Scanner; class Bubble{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int a[] = new int[15]; System.out.println("Enter 15 integers:"); for(int i = 0; i < a.length; i++) a[i] = Integer.parseInt(in.nextLine()); for(int i = 0; i < a.length; i++){ for(int j = 0; j < a.length - 1 - i; j++){ if(a[j] > a[j + 1]){ int temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } System.out.println("Sorted list:"); for(int i = 0; i < a.length; i++) System.out.println(a[i] + " "); System.out.println(); } }

Output

 
 OUTPUT : 
Enter 15 integers:
5
2
8
11
9
12
1
7
3
13
10
4
14
15
6
Sorted list:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15