1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter three numbers: "); 9 double n1 = input.nextDouble(); 10 double n2 = input.nextDouble(); 11 double n3 = input.nextDouble(); 12 13 input.close(); 14 15 displaySortedNumbers(n1, n2, n3); 16 } 17 18 public static void displaySortedNumbers(double num1, double num2, double num3) 19 { 20 if(num1 > num2 && num1 > num3) 21 { 22 if(num2 > num3) 23 System.out.println(num3 + " " + num2 + " " + num1); 24 else 25 System.out.println(num2 + " " + num3 + " " + num1); 26 } 27 else if(num2 > num1 && num2 > num3) 28 { 29 if(num1 > num3) 30 System.out.println(num3 + " " + num1 + " " + num2); 31 else 32 System.out.println(num1 + " " + num3 + " " + num2); 33 } 34 else if(num3 > num1 && num3 > num2) 35 { 36 if(num1 > num2) 37 System.out.println(num2 + " " + num1 + " " + num3); 38 else 39 System.out.println(num1 + " " + num2 + " " + num3); 40 } 41 } 42 }
时间: 2025-01-06 09:21:33