| Author |
Whats the output...
|
Mohnish Khiani
Ranch Hand
Joined: May 17, 2010
Posts: 65
|
|
The Output given is 21... I couldn't understand how...please explain..
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Do you run it using IDE like Eclipse?
You could check how the code executes using debug mode.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
The main consideration is the lack of break statements. That means that if roman == Roman.X three switch statements will be executed:
- roman = Roman.C;
- if(roman.ordinal>2)z+=5;
- x++
Now just loop through the code; I suggest you do it manually. Like this:
- start: x == 7, z == 2, roman == X
- iteration 1: roman == X so roman = C, z += 5, x++, and another z++. At the end, x == 8, z == 8 and roman == C
- iteration 2: ...
Renamed your Roman variable because the forum won't let me use its name outside code blocks.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
And the code as it is, can't compile...
HINT: Error is in line 14 (maybe just a small typo)
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Mohnish Khiani
Ranch Hand
Joined: May 17, 2010
Posts: 65
|
|
|
sorry for that...that was my typing error...
|
 |
Mohnish Khiani
Ranch Hand
Joined: May 17, 2010
Posts: 65
|
|
|
hey...sorry and thanks for your replys i got it...i was making a silly mistake...thanks everyone
|
 |
 |
|
|
subject: Whats the output...
|
|
|