輸入字符串“1”,無法判斷
package ProjectAnswer;
import java.util.Scanner;
public class Text {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("歡迎使用答答租車系統(tǒng):");
System.out.println("您是否要租車:1是 0否");
String a;
do {
a=input.nextLine();
if("1"==a) {
System.out.println("您可租用的類型及其價目表:");
System.out.println("序號? ?汽車名稱? ? ? ? 租金? ? ? ? ? ? ? ? ?容量");
System.out.println("1.? 奧迪A4? 500元/天? ? ? 載人:4人");
System.out.println("2.? 馬自達6? 400元/天? ? ? 載人:4人");
System.out.println("3.? 皮卡雪6? 450元/天? ? ? 載人:4人 載貨:20噸");
System.out.println("4.? 金龍? ? ? ? ? ? 800元/天? ? ? 載人:20人");
System.out.println("5.? 松花江? ? ? ? 400元/天? ? ? 載人:4噸");
System.out.println("6.? 依維柯? ? ? ?1000元/天? ? ?載人:20噸");
break;
}else if("0"==a){
System.out.println("歡迎再次使用答答租車系統(tǒng)!");
break;
}
else {
System.out.println("您輸入錯誤,請重新輸入!");
}
}while("0"!=a&&"1"!=a);
}
}
輸出結(jié)果:
歡迎使用答答租車系統(tǒng):
您是否要租車:1是 0否
1
1
您輸入錯誤,請重新輸入!
1
1
您輸入錯誤,請重新輸入!
1
2019-05-16
為什么不使用switch來的更方便。
2019-05-01
使用a.equals("1")來判斷就好了