Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. why this SCJP program gives output 21 but I am getting 20?
  2. public class Stepper
  3. {
  4. enum Roman {I,V,X,L,C,M}
  5. public static void main(String... args)
  6. {
  7.     int x=7;
  8.     int z=2;
  9.     Roman r = Roman.X;
  10.     do
  11.     {
  12.         switch(r)
  13.         {
  14.             case C : r = Roman.L;break;
  15.             case X : r = Roman.C;
  16.             case L : if(r.ordinal()>2)
  17.                         {
  18.                             z += 5;//7,13,19
  19.                         }
  20.             case M : x++;//8,9,10
  21.         }
  22.         z++;//8,14,20
  23.     }
  24.     while (x<10);
  25.     System.out.println(z); //
  26. }
  27. }
  28.        
  29. case C : r = Roman.L;
  30. break;