2021-01-04 09:07开始学习
复习题2.1
import java.util.Scanner; public class CelsiusToFahrenheit { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter a degree in Celsius: "); double celsius = input.nextDouble(); double fahrenheit = (9.0 / 5) * celsius + 32; System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit"); } }
复习题2.2
import java.util.Scanner; public class Cylinder { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter the radius and length of a cylinder: "); double radius = input.nextDouble(); double length = input.nextDouble(); final double p = 3.14159; double area = radius * radius * p; double volume = area * length; System.out.println("The volume is " + volume); } }