import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double d = scanner.nextDouble();
System.out.println(Main.typeConversion(d));
}
public static int typeConversion(double d){
int a = (int)d;
return a;
}
}
在这里根据题目要求,我们是想要的到一个int类型的值,也就是说我们要把typeConversion里传入参数d强转成int类型.强转的语法格式:在圆括号里给出想要的转换的目标类型,后面紧跟带转换的变量名. eg:double x = 9.997; int nx = (int) x;