Computer Applications
Write a program to input and sort the weight of ten people. Sort and display them in descending order using the selection sort technique.
Java
Java Arrays
ICSE 2011
81 Likes
Answer
import java.util.Scanner;
public class KboatSelectionSort
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double weightArr[] = new double[10];
System.out.println("Enter weights of 10 people: ");
for (int i = 0; i < 10; i++) {
weightArr[i] = in.nextDouble();
}
for (int i = 0; i < 9; i++) {
int idx = i;
for (int j = i + 1; j < 10; j++) {
if (weightArr[j] > weightArr[idx])
idx = j;
}
double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}
System.out.println("Sorted Weights Array:");
for (int i = 0; i < 10; i++) {
System.out.print(weightArr[i] + " ");
}
}
}Output

Answered By
26 Likes
Related Questions
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
The statement used to find the total number of Strings present in the string array String s[] is:
- s.length
- s.length()
- length(s)
- len(s)