第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何解決輸入中“nextLine()”的問題

如何解決輸入中“nextLine()”的問題

慕哥9229398 2023-06-21 15:02:46
我能理解為什么nextLine()不起作用。如果我改變nextLine()我next()的輸入不會接受所有短語 case 7:        System.out.println("Press 1 to post on your wall \nPress 2 to post on a friend's wall");        int b=scan.nextInt();        if(b==1){            System.out.println("What do you want to post?");            String pm=scan.nextLine();            Message ms= new Message(loginUser.getUsername(),loginUser.getUsername() +" :"+ pm.toString());            message.add(ms);        }        if(b==2){            System.out.println("Whose wall do you want to post? (Write his/her username)");            String ph=scan.next();            for(int n = 0;  n< users.size(); n++)            {                if(!loginUser.getUsername().equals(ph)                         && users.get(n).getUsername().equals(ph)){                    System.out.println("What do you want to post?");                    String postIt=scan.nextLine();                    Message me= new Message( ph,ph +" : "+loginUser.getUsername() +" : " + postIt.toString() );                    message.add(me);                }            }        }         luna=false;        break;
查看完整描述

1 回答

?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

scan.nextLine()您需要在調(diào)用后添加一個調(diào)用scan.nextInt();,而不是使用其中的值:

int b=scan.nextInt();
scan.nextLine(); //Add this line

這是因為nextInt()不會消耗用于nextLine()確定行結束的行終止符,并且額外的調(diào)用nextLine()將正確地為您消耗它。

基本上,在你給它賦值之前2,例如,nextInt()將采用2,然后nextLine()將采用2THAT 行之后的所有內(nèi)容,這將是什么。

next如果您將ornextInt與混合使用,則始終需要執(zhí)行此操作nextLine。


查看完整回答
反對 回復 2023-06-21
  • 1 回答
  • 0 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號