Life long sharing . . .

Java – “if-else” and “switch” statement

Posted on: November 24, 2015

Here is a summary from http://www.tutorialspoint.com/java/switch_statement_in_java.htm

Lesson6-note1

Now, look at the below switch codes. What do you the output will be?

Lesson6-code1

No. It is NOT “You passed. Your grade is D”. The output is:

Lesson6-output1

Why? Because there is a missing “break;” after line 16 in the code. The statements following that ‘D’ case will execute until a break statement is reached, which is at line 19.

Advertisements

1 Response to "Java – “if-else” and “switch” statement"

You passed
Better try again
Your grade is D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives

November 2015
M T W T F S S
« Oct   Dec »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 180 other followers

%d bloggers like this: