HW5.8

 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", "Celsius", "Fahrenheit", "Fahrenheit", "Celsius");
 6
 7         for(double i = 40, j = 120; i >= 31 && j >= 30; i--, j -= 10)
 8             System.out.printf("%.1f\t%.2f\t%.1f\t%.2f\n", i, celsiusToFahrenheit(i), j, fahrenheitToCelsius(j));
 9     }
10
11     public static double celsiusToFahrenheit(double celsius)
12     { return (9.0 / 5) * celsius + 32; }
13
14     public static double fahrenheitToCelsius(double fahrenheit)
15     { return (5.0 / 9) * (fahrenheit - 32); }
16 }
时间: 2024-10-12 03:38:23

HW5.8的相关文章

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