我的题解 | 类型转换
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){ //装箱给Double Double dou = d; return dou.intValue(); } }
装箱给Double类型然后通过intValue方法转换成int