我想我的程序驗證使用兩個單字符是由用戶輸入,它必須是A或M.驗證單個字符JAVA
之間這裏是我的代碼我迄今:
static char getCustomerType() {
System.out.println("Please enter the term for the Policy the client would like");
System.out.println("A for Annual or M for Monthly. Annual provides the user with a 10% discount");
String s = inputs.next();
while (s != 'A' && s != 'M') {
System.out.println("Incorrect, please try again");
s = inputs.next();
}
}
的Netbeans然而,當我已經把它while語句之前使用不喜歡這個陳述inputs.next是從未使用過? 它也不喜歡生成不兼容的字符串類型引用布爾型爲字符串的while語句。
我認爲這是因爲我已經聲明s爲一個字符串?
一個'String'不是'char'和'!='不同於'! ='... – fvu
[如何比較Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – moe
更改爲字符串並將其更改爲!=,拋出錯誤即使將方法從Char更改爲String並將「s」更改爲「letter」,String仍然無法轉換爲布爾值,並仍然針對char操作數類型拋出錯誤 – FUBAR