ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2011 ICSE Computer Science Paper



Share with a Friend

Solved 2011 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Descending Order - Selection Sort Program - ICSE 2011 Computer Science

Write a program to input and sort the weight of ten people. Sort and display them in descending order using the selection sort technique.

import java.util.Scanner; class Weight{ public static void main(String args[]){ Scanner in = new Scanner(System.in); double w[] = new double[10]; System.out.println("Weight of 10 people:"); for(int i = 0; i < w.length; i++) w[i] = Double.parseDouble(in.nextLine()); for(int i = 0; i < w.length; i++){ double large = w[i]; int pos = i; for(int j = i + 1; j < w.length; j++){ if(large < w[j]){ large = w[j]; pos = j; } } double temp = w[i]; w[i] = large; w[pos] = temp; } System.out.println("Weight in descending order:"); for(int i = 0; i < w.length; i++) System.out.println(w[i]); } }

Output

 
 OUTPUT : 
Weight of 10 people:
56
76
89
93
51
60
58
82
78
81
Weight in descending order:
93.0
89.0
82.0
81.0
78.0
76.0
60.0
58.0
56.0
51.0