HW5.5

 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

HW5.5的相关文章

HW5.1

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int count = 0; 6 7 for(int i = 1; i <= 100; i++) 8 { 9 System.out.print(getPentagonalNumber(i) + " "); 10 count++; 11 12 if(count == 10) 13 { 14 System.out.println();

HW5.14

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 10; i <= 100; i += 10) 8 System.out.printf("%d\t%f\n", i, getMi(i * 1.0)); 9

HW5.2

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 the number: "); 9 long number = input.nextLong(); 10 11 input.close(); 12

HW5.13

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 1; i <= 20; i++) 8 System.out.printf("%d\t%f\n", i, getMi(1.0 * i)); 9 } 10 1

HW5.10

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int count = 0; 6 7 for(int i = 1; i < 10000; i++) 8 if(isPrime(i)) 9 count++; 10 11 System.out.println("The count of the prime number smaller than 10000 is: " + count)

HW5.30

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 3; i <= 1000; i++) 6 if(isDoublePrime(i)) 7 System.out.println("(" + i + ", " + (i + 2) + ")"); 8 } 9 10 public static boolean isDouble

HW5.4

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 a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 r

HW5.32

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int n1 = (int)(Math.random() * 5 + 1); 6 int n2 = (int)(Math.random() * 5 + 1); 7 int winCount = 0; 8 9 for(int i = 0; i < 10000; i++) 10 { 11 if(diceGame(n1, n2)) 12 winCount

HW5.9

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\t%s\t%s\n", "Inch", "Meter", "Meter", "Inch"); 6 7 for(double i = 1, j = 20; i <= 10 && j <

HW5.3

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 a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 S