import java.io.*;
public class chang
{
public static void main(String args[])throws IOException
{
float nt,dollor;
BufferedReader buf;
String str,chose;
do{
System.out.println("(1)dollor to NT (2)NT to dollor,if leaf express exit");
buf = new BufferedReader(new InputStreamReader(System.in));
chose = buf.readLine();
//System.out.println(chose);
if(chose.equals("1"))
{
str = buf.readLine();
dollor = Float.parseFloat(str);
nt = dollor * 32.61f;
System.out.println(dollor + " is " + nt + "NT");
}
else if(chose.equals("2"))
{
str = buf.readLine();
nt = Float.parseFloat(str);
dollor = (1/32.61f) * nt;
System.out.println(nt + "is" + dollor + "dollor");
}
}while(!chose.equals("exit"));
System.out.println("thnx.");
}
}
A:
我覺得在文字比較時,要用equals
因為== 是在比較存放Heap 的位址,所以得fales.
A:
判斷字串最好用equals方法
沒有留言:
張貼留言