여기 소스 코드의 중요한 비트이다 :왜이 라인을 건너 뛰고 있습니까? (자바)
#of 0's: 0
#of 1's: 0
#of 2's: 0
#of 3's: 0
#of 4's: 0
#of 5's: 0
#of 6's: 0
:
class Dice
{
String name ;
int x ;
int[] sum ;
는 ...
public Dice (String name)
{
this.name = name ;
this.x = 0 ;
this.sum = new int[7] ;
}
여기 ...
public static void main (String[] arg)
{
Dice a1 = new Dice ("a1") ;
printValues (a1) ;
}
public static void printDice (Dice Dice)
{
System.out.println (Dice.name) ;
System.out.println ("value: "+Dice.x) ;
printValues (Dice) ;
}
public static void printValues (Dice Dice)
{
for (int i = 0; i<Dice.sum.length; i++)
System.out.println ("#of "+i+"'s: "+Dice.sum[i]) ;
}
}
가 출력되고
왜이 두 라인은 printDice
내부 실행하지 못했습니다 : #of
의
System.out.println (Dice.name) ;
System.out.println ("value: "+Dice.x) ;
가 있었다면 그때 "A1"과 "0 값"을 참조하십시오 기대
이런 종류의 좋은 전략은 처음부터 코드를 단계별로 실행하여 코드를 손으로 추적하고 코드가 어디에 있는지 확인하고 코드가 말하는 위치가 아닌 곳으로 이동하는 것입니다. –
'Dice.name' 클래스는'Dice' 클래스의 정적 필드'name'에 액세스하려는 것처럼 보이기 때문에 클래스와 같은 변수 이름을 지정하지 않아야하지만 실제로 객체의 필드에 액세스하려고합니다. http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html – Progman