죄송합니다. int를 반환하는 메서드를 호출하려고하지만 내 문자열 변수에 전달하려는 프로그램과 매우 혼동스러워집니다. 메소드에서 작동하는 코드가 이미 있지만, 이제 checkMatchesSomewhere()를 호출하여 자체 메소드로 이동했습니다.문자열 값을 메서드에 전달합니다.
문자열 변수 secretWord 및 secretGuess 값을 메서드에 전달하여 루프에서 사용할 수 있도록하려는 경우. 그러나 그것은 컴파일되지 않습니다. 누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 많은 감사합니다. 나는 프로그래밍에 초보적이다.
class App
{
public static void main(String args[])
{
App app = new App();
}
//constructor
public App()
{
//variables
String secretWord = "berry";
String guessword = "furry";
secretMatches = 0;
//Call CheckMatchesSomewhere method
checkMatchesSomewhere(secretword, guessword); // checks number of matches somewhere in the secretWord
// print the number of times the secretChar occurs in the string word
System.out.println(secretMatches);
}
// METHOD THAT CHECKS FOR NUMBER OF MATCHES SOMEWHERE IN THE WORD
private int checkMatchesSomewhere(String secretword, String guessword)
{
// variables
String secretWord;
String guessWord;
int secretMatches = 0;
//check each letter in sequence against the secretChar
//
//a loop which reads through 'secretWord'
for (int j = 0; j < secretWord.length(); j++)
{
//the loop which goes through 'word'
for (int i = 0; i < guessWord.length(); i++)
{
if (guessWord.charAt(i) == secretWord.charAt(j))
{
secretMatches++;
//break once a match is found anywhere
break;
}
} // end word for loop
} // end secretWord for loop
// return the number of matches somewhere
return secretMatches;
}
}
어떤 오류가 있습니까? BTW, 모든 문자가 같은지 확인하는 대신 '평등'을 사용하는 것이 어떻습니까? ... – Maroun
죄송합니다. 오류가 발생했습니다. 기호를 찾을 수 없습니다. \t \t checkMatchesSomewhere (secretword, guessword); //은 SECRETWORD \t \t^ 기호 어딘가에 일치의 수를 확인 : 변수 SECRETWORD에게 위치 : 클래스 앱 을 내가 CheckMatchesSomewhere (...) –
나는 매우에 좋은 초보자의 책으로 시작하는 것이 좋습니다 것입니다 메서드를 호출 라인에 Java 또는 Oracle의 자습서 여기에는 절대적인 기초에 대해 확실하게 이해하지 못한다는 여러 가지 문제가 있습니다. –