Online Java Compiler By
JavaTpoint.com
import java.util.Scanner; public class Double_maxMethodExample3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter number of elements you want."); int n = scanner.nextInt(); Double a[] = new Double[n]; System.out.println("Enter elements"); for (int i = 0; i < n; i++) { a[i] = scanner.nextDouble(); } Double f1, temp = 0.0; for (int i = 0; i < n ; i++) { for (int j = i+1; j < n; j++) { f1 = Double.max(a[i], a[j]); if (a[i].equals(f1)){ //temp = f1; a[i] = a[j]; a[j] = f1; } } } System.out.print("Descending order = "); for (int i = n-1; i >=0; i--) { System.out.print(a[i]+","); } } }
Output