String s; //contains the main string i have to input
String s1; //is the set of the 1st and 3rd word
String st; //st is to get the 3 words separately
char c;
int i;
int l=s.length();//l is for length of string
for(i=0;i<l;i++){
c=s.charAt(i);
if(c==' '){
if(st.equals("Middle")){
st="";
}
else{
s1=s1+" "+st;
st="";
}
}
else{st=st+c;}
}
System.out.println(s1);
나는이 질문에 3 시간을 보냈지 만, 왜 내 코드가 첫 번째 단어를 출력하여 실행하는지 디버그 할 수 없으며 나머지 단어는 2 단어 만 남기고 싶습니다. 나는이 프로그램을 실행하는 방법을 알고 있지만이 방법은 새로운 무엇이 잘못 된지 모르겠다.어떻게 3 단어의 문자열에서 중간 단어를 제거합니까?
[mcve] – Jens
을 제공하십시오.'l','st' 및'c'는 무엇입니까? – Mistalis