亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

學號出現重復 但是不被識別 依然收錄

學號出現重復 但是不被識別 依然收錄

C
慕絲9287860 2017-10-26 22:56:20
for (int i = 0; i < a.length; i++) {?????System.out.println("輸入你要增加學員的學號:");?????int xh = input.nextInt();?????boolean f = false;?????if (xh > 000 && xh < 100) {??????for (int j = 0; j < a.length; j++) {???????if (xh!=a[i].getId()) {????????f = true;????????System.out.println("hah ");????????break;???????}??????}??????if (f = true) {???????a[i].setId(xh);???????System.out.println("恭喜你,學員學號錄入成功");???????break;??????} else {???????a[i].setId(xh);???????System.out.println("抱歉,學號已存在");???????break;??????}?????} else {??????System.out.println("學號是這樣滴?");?????}????}
查看完整描述

1 回答

已采納
?
習慣受傷

TA貢獻885條經驗 獲得超1144個贊

有好幾處邏輯錯誤,第一段:
boolean f = false;
???? if (xh > 000 && xh < 100) {
????? for (int j = 0; j < a.length; j++) {
?????? if (xh!=a[i].getId()) {
??????? f = true;
??????? System.out.println("hah ");
??????? break;
?????? }
????? }
這里你的本意是判斷是否有重復對吧?那應該是這樣的:
boolean f = false;
???? if (xh > 000 && xh < 100) {
????? for (int j = 0; j < a.length; j++) {
?????? if (xh==a[i].getId()) {? //這里,只有相等了才會標記為true。
??????? f = true;
??????? System.out.println("Exist! ");
??????? break;
?????? }
????? }
第二個錯誤:
if(f=true)
應該為:
if(f)? 或者寫作? if(f==true)

查看完整回答
2 反對 回復 2017-10-27
  • 1 回答
  • 0 關注
  • 920 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號