ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2008 ICSE Computer Science Paper



Share with a Friend

Solved 2008 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Sort String Bubble Sort Program - ICSE 2008 Computer Science

Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order using the bubble sort technique only.

INPUT: Delhi, Bangalore, Agra, Mumbai, Calcutta
OUTPUT: Agra, Bangalore, Calcutta, Delhi, Mumbai

class Bubble{ public static void main(String args[]){ String a[] = {"Delhi", "Bangalore", "Agra", "Mumbai", "Calcutta"}; for(int i = 0; i < a.length; i++){ for(int j = 0; j < a.length - 1 - i; j++){ if(a[j].compareTo(a[j + 1]) > 0){ String 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.print(a[i] + " "); System.out.println(); } }

Output

 
 OUTPUT : 
Sorted List:
Agra Bangalore Calcutta Delhi Mumbai