-2
사용자가 문자열을 입력하고 여러 단어 중간에 제거 할 공간이 필요한 코드가 있습니다.문자열에서 공백을 제거하는 방법은 무엇입니까?
`System.out.println("Enter your choice:\n"
+ "Type 'Player Name' to search for a player based off their name.\n"
+ "Type 'Player School' to search for a player based off their school\n"
+ "Type 'Team Location' to search for a team based off their location.\n"
+ "Type 'Team Mascot' to search for a team based off their mascot.\n");
String choice = input.next();
choice = choice.replaceAll("\\s+", "");
System.out.println(choice);
switch(choice.toLowerCase()){
case "playername":
searchPlayer();
break;
case "playerschool":
searchSchool();
break;
case "teamlocation":
searchLocation();
break;
case "teammascot":
searchMascot();
break;
default:
System.out.println("Yet to be implemented");
break;
}`
이 그러나 나에게 오류를 제공하지 않습니다 항상 내가 공백이 포함 된 기본 케이스를 반환 여기
내가 가진 것입니다. 나는 그것이 작동하지 않는 이유를보기 위해 선택 사항을 인쇄하기 위해 줄을 넣었고, 이것을 실행할 때 첫 단어 만 유지합니다. 예를 들어 "Player Name"을 입력하면 "player"가 반환됩니다.
'next()'에 대한 문서를 찾았습니까? – Henry
콘솔 출력이란 무엇입니까? –