/**
* @param tW 华氏温度
* @return 摄氏温度
*/
public static float W2C(float tW)
{
return (tW-32)*5/9
}
/**
* 摄氏温度转华氏温度
* @param tC 摄氏温度
* @return 华氏温度
*/
public static float C2W(float tC)
{
return 9*tC/5+32
}
/**
* @param args
*/
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
intln(Main.W2C(100)) // 华氏100度转摄氏温度
intln(Main.C2W(100)) // 摄氏100度转华氏温度
}
}
你一直在重复的给f赋值,我刚写了下,给你参考,代码贴在下面,选我下哦
import java.util.Scannerpublic class Work1
{
public static void main(String[] args)
{
double a
double b
System.out.println("请选择温度种类:1,摄氏度转华氏度 2,华氏度转摄氏度")
Scanner change = new Scanner(System.in)
double g = change.nextInt()
System.out.println("请输入需要转换的温度:")
Scanner changedegree = new Scanner(System.in)
double f = changedegree.nextDouble()
if (g == 1)
{
a = f * 9 / 5 + 32
System.out.println("华氏度为:" + a)
} else if (g == 2)
{
b = (f - 32) * 5 / 9
System.out.println("摄氏度为" + b)
}
}
}
doublehuashi
double
sheshi
=
0.0
int
printOutCnt
=
0
do
{
huashi
=
sheshi
*
9
/
5.0
+
32
if
(printOutCnt
<
10)
{
System.out.println("huashi(%d)→sheshi(%d)",
huashi,
sheshi)
printOutCnt++
}
sheshi
=
sheshi
+
20
}while(sheshi
>=
0
&&
sheshi
<=
250)
0-250每隔20个刻度明显要输出13条,最多只让输出10条,肯定不可能全输出出来,太坑人了。。。这样看更简单一些,如果要求超过10条退出的话,可以直接在while条件里写
while(sheshi
>=
0
&&
sheshi
<=
250
&&
printOutCnt
<
10)