내 논리가 괜찮은 것처럼 느껴집니다. 나는 완전히 잃어버린 것처럼 느껴지지 않는다. 그러나, 나는 정확히 내가 뭘 잘못하고 있는지 알아. 부분 문자열의 시작 색인은 항상 찾을 수 있지만 사용자가 부분 문자열로 입력 한 단어의 색인의 전체 개수 (예 : 3,4,5,6)는 절대로 찾을 수 없습니다.하위 문자열의 각 문자 색인 찾기
나는 이것을 1 주일 동안 혼자서하는 방법을 찾아 내려고 노력했다. 나는 그것을 올바르게 할 수 없다.
import java.util.Scanner;
public class midterm
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
String simplePhrase;
String portionPhrase;
int portionIndex;
int portionCount;
int portionIndexTotal;
System.out.println("Enter a simple phrase:");
simplePhrase = keyboard.nextLine();
int phraseLength = simplePhrase.length();
System.out.println("Phrase length:" +phraseLength);
System.out.println("Enter a portion of previous phrase:");
portionPhrase = keyboard.nextLine();
String portionPhraseSub = simplePhrase.substring(portionPhrase);
portionIndex = simplePhrase.indexOf(portionPhraseSub);
for (portionIndex; portionIndex <= portionPhrase; portionIndex++)
{
System.out.println("Portion phrase index:"+portionIndex);
}
}
}
'partialPhrase'의 타입이'String' 일 때'portionIndex <= partPhrase'는 의미가 없습니다 ... (처음 사용했을 때 변수를 선언했다면 코드가 더 읽기 쉬울 것입니다.) –
컴파일 된 것을 게시하십시오. 이'String partPhraseSub = simplePhrase.substring (partialPhrase);'는 컴파일되지 않습니다. – dasblinkenlight
'simplePhrase.substring (partialPhrase)'는'partialPhrase'가 문자열 일 때도 무엇을 의미합니까? –