Computer Science, asked by pratishmoses, 9 months ago

Write a programin Java that asks the user to enter an integer (N). Create a single-dimensional
array of N double values. Ask the user to enter the N double values to populate this array.
Sort this array in reverse (descending) order using the selection sort method, and print the
same on a single line, each element separated by a space

Answers

Answered by Anonymous
1

Answer:

import java.util.Scanner;

class BubbleSortExample {

public static void main(String []args) {

int num, i, j, temp;

Scanner input = new Scanner(System.in);

System.out.println("Enter the number of integers to sort:");

num = input.nextInt();

int array[] = new int[num];

System.out.println("Enter " + num + " integers: ");

for (i = 0; i < num; i++)

array[i] = input.nextInt();

for (i = 0; i < ( num - 1 ); i++) {

for (j = 0; j < num - i - 1; j++) {

if (array[j] > array[j+1])

{

temp = array[j];

array[j] = array[j+1];

array[j+1] = temp;

}

}

}

System.out.println("Sorted list of integers:");

for (i = 0; i < num; i++)

System.out.println(array[i]);

}

}

Similar questions