如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(foot+inch/12)×0.3048。现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12英寸。
输入格式:
输入在一行中给出1个正整数,单位是厘米。
输出格式:
在一行中输出这个厘米数对应英制长度的英尺和英寸的整数值,中间用空格分开。
输入样例:
170
输出样例:
5 6
package test1
import java.util.*
/**
*
*/
fun main(args: Array<String>) { // 包级可见的函数,接受一个字符串数组作为参数
/*获取对应的输入流*/
val scanf = Scanner(System.`in`)
/*定义变量*/
var length: Int
/*接收输入值*/
length = scanf.nextInt()
scanf.close()
var foot: Double
/*计算*/
foot = computeFoot(length / 100.0)
var inch: Double
/*计算*/
inch = computeInch(length / 100.0)
print( foot.toInt() )
print(" ")
print(inch.toInt())
}
/**
* 厘米转英寸
* (foot + inch / 12 ) * 0.3048 = length
*/
fun computeInch(length: Double): Double {
val foot = computeFoot(length)
var compute: Double
compute = foot - foot.toInt()
return compute * 12
}
/**
* 里面转英尺
*/
fun computeFoot(length: Double): Double {
return length / 0.3048
}