0
public class Stepper 
{
enum Roman {I,V,X,L,C,M}
public static void main(String... args) 
{
    int x=7;
    int z=2;
    Roman r = Roman.X;
    do
    {
        switch(r)
        {
            case C : r = Roman.L;break;
            case X : r = Roman.C;
            case L : if(r.ordinal()>2) 
                        {
                            z += 5;//7,13,19
                        }
            case M : x++;//8,9,10
        }
        z++;//8,14,20
    }
    while (x<10);
    System.out.println(z); //
}
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Hello all i am preparing for SCJP exams ... In the above program When manually done output of the program is 20 but through jvm its 21 ... correct me thank you in advance – Java Professional Jun 11 '12 at 11:42
  • 2
    See: http://www.coderanch.com/t/258402/java-programmer-SCJP/certification/Enum – Paul R Jun 11 '12 at 11:44
  • 1
    If there is a dfference between what you expect a program to do and what is does, the first thing you should try is to step through the code with your debugger. This will show you the values of all the variables after each line of code. – Peter Lawrey Jun 11 '12 at 11:56

1 Answers1

3

When r = Roman.C,

case C : r = Roman.L;
break;

after case C executed the break, there's a z++ right after the break.

You missed that one.

Lai Xin Chu
  • 2,462
  • 15
  • 29