在第一步驟,打算用循環(huán)語(yǔ)句來(lái)判斷輸入的數(shù)字,但不知道哪里出錯(cuò)了.求各位幫幫忙看一下.我的思路是:通過(guò)輸入數(shù)字0或1來(lái)代表"否"和"是",①判斷輸入的是否是0或1,②真:繼續(xù)判斷是0還是1,給出具體的應(yīng)答;否,重新輸入.
package com.imooc;
import java.util.Scanner;
public class Initial {
? ? public static ?int inPut1;
? ??
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ??
Scanner input1 = new Scanner(System.in);//獲取用戶輸入的指令
? ? ? ? System.out.println("您是否想要租車? ");
? ? ? ? System.out.println("是,請(qǐng)回復(fù)1;否,請(qǐng)回復(fù)0");
? ? ? ? inPut1 = input1.nextInt();
? ? ? ? ?
? ? ? ? ? ? if ((inPut1 != 0 )|| (inPut1 != 1)){
? ? ? ? ? ? do {
? ? ? ? ? ?Scanner input1a = new Scanner(System.in);
? ? ? ? ? ?System.out.println("請(qǐng)輸入數(shù)字1或0.1表示'是';0表示'否'.");
? ? ? ? ? ?inPut1= input1a.nextInt();
? ? ? ? ? ?//continue;
? ? ? ? ? ? }while ( (inPut1 != 0) ||(inPut1 != 1));
? ? ? ? ? ? }else{
? ? ? ? ? ? switch (inPut1){
? ? ? ? ? ?case 0:
? ? ? ? ? ? ? ?System.out.println("退出 答答打車 程序");
? ? ? ? ? ?case 1:
? ? ? ? ? ? ? ?System.out.println("您可租車的類型與及其價(jià)格表,如下:");
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ?}
? ? ? ? ? ?
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ?
}
? ? ? ? //調(diào)用各類汽車的型號(hào)價(jià)目表
2016-08-20
while中的條件錯(cuò)了,||邏輯運(yùn)算符的規(guī)則是有任一條件為true,則返回true。所以你寫成這樣,除非這世上有一個(gè)數(shù)可以同時(shí)等于0和1才能使這個(gè)條件為false從而退出循環(huán)
2016-08-20
補(bǔ)充一下. 我做過(guò)debug測(cè)試,問(wèn)題是在循環(huán)語(yǔ)句哪里,不論我輸入什么數(shù)字,都跳不出循環(huán).主要想問(wèn)一下為什么會(huì)出現(xiàn)這樣的情況.