Why are these lines being skipped? (java)

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-04-14T20:19:09Z Indexed on 2010/04/14 20:23 UTC
Read the original article Hit count: 194

Filed under:
|
|

Here's the relevant bit of the source code:

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]) ; 
    } 

}

Here is the output:

#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

Why didn't these two lines execute inside printDice:

    System.out.println (Dice.name) ; 
    System.out.println ("value: "+Dice.x) ; 

if they had then i would expect to see "a1" and "Value: 0" printed at the top of the rows of #of's

© Stack Overflow or respective owner

Related posts about java

Related posts about method