public class SimpleDotComTestDrive {
public static void main(String[] args) {
SimpleDotCom dot = new SimpleDotCom();
int[] locations = {2,3,4};
dot.setLocationCells(locations);
String userGuess = "2";
String result = dot.checkYourself(userGuess);//==result==hit
userGuess = "3";
result = dot.checkYourself(userGuess);
userGuess = "4";
result = dot.checkYourself(userGuess);
}
}
class SimpleDotCom{
int [] locationCells;
int numOfHits = 0;
public void setLocationCells (int[] locs) {
locationCells = locs; // {2,3,4}
}
public String checkYourself(String stringGuess) {
int guess = Integer.parseInt(stringGuess);
String result = "miss";
for(int cell : locationCells) {
if(guess== cell) {
result = "hit";
numOfHits++;
System.out.println(numOfHits);
break;
}
}
System.out.println(result);
if (numOfHits == locationCells.length) {
result = "kill";
System.out.println(result);
}
return result;
}
}
위의 코드에서 return result;
의 의미를 잘 모르겠습니다.
SimpleDotComTestDrive안에 있는 result의 값은
SimpleDotComTestDrive 클래스는 void 값을 갖기 때문에 return값이 없다고 배웠는데
return result;의 이유가 정말 궁금합니다.