글쓴이 :김진호 1999년 4월 10일 09:57:59
In Reply to: 초보잔데.. string 출력이 .... posted by 배진호 on 1999년 4월 10일 01:26:09:
소스를 고쳐서 올려 놓았습니다.
String[] lastNames = {"Sosa","Grace","Wood","Gaetti"};
이러한 문장은 배열의 초기화시에만 쓰이는 걸로 알고있습니다. 제가보기에 처음에 초기화를 하시고 main문 안에서 다시 초기화를 시키셨습니다.의도는 값을 할당 하시려한 것같은데.그리고 main문안에서 멤버변수를 부를 때 t라는 이름으로 인스턴스화 하셨으니까t.lastNames[0]과 같은 식으로 불러야 할것같은데요....
class Names{
String[] firstNames = {"Sammy","Mark","Kerry","Gary"};
String[] lastNames= new String[firstNames.length] ;
void printNames() {
for (int i = 0; i < firstNames.length; i++)
{
System.out.println("name : " + firstNames[i]+ lastNames[i] );
}
}
public static void main(String[] args){
Names t = new Names( );
t.lastNames[0] = "Sosa";
t.lastNames[1] = "Grace";
t.lastNames[2] = "Wood";
t.lastNames[3] = "Gaetti";
t.printNames();
}
}