我能理解为什么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;
桃花长相依
相关分类