public class Char{ public static void main(String[] args) { double hua = 199.9; double sheshi = 5 / 9 *(hua - 100); System.out.println("华氏温度" + hua +" 对应温度= " + sheshi); System.out.println( 59 % 7 ); } }
时间: 2024-03-30 12:34:45 浏览: 9
这是一个Java程序,输出华氏温度199.9对应的摄氏温度以及59除以7的余数。
具体解释如下:
1. 定义一个名为Char的类。
2. 在类中定义一个名为main的静态方法,该方法是Java程序的入口点。
3. 在main方法中,定义一个名为hua的double类型变量,并赋初值199.9,表示华氏温度。
4. 计算华氏温度对应的摄氏温度,并将结果赋给名为sheshi的double类型变量。
5. 使用System.out.println方法输出华氏温度和对应的摄氏温度。
6. 使用System.out.println方法输出59除以7的余数。
相关问题
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num1 = sc.nextInt(); int num2 = sc.nextInt(); /********* Begin *********/ System.out.println(num1/num2); /********* End *********/ } }
在 Begin - End 区域内进行代码补充,处理整数除法异常:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
try {
/********* Begin *********/
System.out.println(num1 / num2);
/********* End *********/
} catch (ArithmeticException e) {
System.out.println("除数不能为0");
}
}
}
```
在代码中使用 `try...catch` 结构捕获整数除法异常,如果出现异常则输出 "除数不能为0"。
帮我找一下错误import java.util.*; public class Main { public static void main(String[] args) { Cylinder sc = new Cylinder(5.0, 6.0); sc.getArea(); sc.getVolume(); } } class Circle { double radius; public Circle() {} public Circle(double radius) { this.radius = radius; } public void getArea() { double area = Math.PI * radius * radius; return area; } } class Cylinder extends Circle { double height; public Cylinder(double radius, double height) { this.radius = radius; this.height = height; } public void getArea() { double area = Math.PI * radius * radius; return area; } public void getVolume() { double volume = getArea * height; return volume; } }
在第三个类Cylinder中,getArea方法和getVolume方法的返回值应该是double类型而不是void类型,同时在getVolume方法中需要调用getArea方法并获取其返回值而不是直接用getArea。正确代码应该是这样的:
import java.util.*;
public class Main {
public static void main(String[] args) {
Cylinder sc = new Cylinder(5.0, 6.0);
sc.getArea();
sc.getVolume();
}
}
class Circle {
double radius;
public Circle() {}
public Circle(double radius) {
this.radius = radius;
}
public double getArea() {
double area = Math.PI * radius * radius;
return area;
}
}
class Cylinder extends Circle {
double height;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double getArea() {
double area = 2 * Math.PI * radius * (radius + height);
return area;
}
public double getVolume() {
double volume = getArea() * height;
return volume;
}
}