英尺和米的转化公式:
1英尺=12英寸=0.3048米
方法一:
int foot; int inch; Scanner in = new Scanner(System.in);foot = in.nextInt(); inch = in.nextInt();System.out.println("foot="+foot+",inch="+inch);System.out.println((foot+inch/12.0)*0.3048);
方法二:
int foot; double inch;Scanner in = new Scanner(System.in);foot = in.nextInt(); inch = in.nextInt();System.out.println("foot="+foot+",inch="+inch);System.out.println((foot+inch/12)*0.3048);
手动强制转化为厘米:
int foot; double inch;Scanner in = new Scanner(System.in);foot = in.nextInt(); inch = in.nextInt();System.out.println("foot="+foot+",inch="+inch);System.out.println((foot+inch/12)*0.3048);//手动强制类型转换System.out.println((int)((foot+inch/12)*0.3048*100)+"cm");