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
77 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
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)
A single dimensional array contains 37 elements. Which of the following represents the index of its second-to-last element.
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033
Name the method of search depicted in the below picture: