Switch Case Condition With Java Program

Switch Case Condition with Java Program

“Switch Case condition” is very popular in java program. If we want to check more than 10 conditions, then we have to use “Switch Case condition” in our java program. But this condition has one limitation; we can only use char and int in this condition with java program. We cannot use with other data type.

 

Switch Case Condition

switch case condition with java program

 

In this image, we can easily understand the “switch case” condition. If condition1 is true then program’s flow goes to Result Statement otherwise goes to Con-2. If Cond-2 is true then Result Statement executes otherwise goes to Con-3. So and so in the else statement we can get final result if all condition is false.

 

 

Program in “Switch Case Condition with Java Program”.

Title : Enter Three Subject Find Total, Per and Grade.

import java.util.*;

class condition4

{

          static void findResult(double x, double y, double z)

{

          double total,per;

          total = x+y+z;

          per = total/3;        // if all subject from 100 marks.

          System.out.println(“Total = ” + total);

          System.out.println(“Per = ” + per);

          int p = (int)(per/10);

          switch(p)

          {

          case 1:

          case 2:

          case 3:

                   System.out.println(“F Grade”);

                   break;

          case 4:

          case 5:

                   System.out.println(“P Grade”);

                   break;

          case 6:

          case 7:

                   System.out.println(“B Grade”);

                   break;

          case 8:

          case 9:

          case 10:

                   System.out.println(“A Grade”);

                   break;

          default:

                   System.out.println(“Something is wrong”);

}

}

          public static void main(String args[])

{

                double m1,m2,m3;

Scanner in1 = new Scanner(System.in);

                   System.out.print(“Enter M1 : ”);

                   m1 = in1.nextDouble(); // Method

                   System.out.print(“Enter M2 : ”);

                   m2 = in1.nextDouble(); // Method

                   System.out.print(“Enter M3 : ”);

                   m3 = in1.nextDouble(0);

                   findResult(m1,m2,m3);

          }

}

Output:

Enter M1: 67

Enter M2: 78

Enter M3: 99

Total = 244.0

Per = 81.333

A Grade

 

Video available on YouTube.

 

 

You can also download java program: Click Here -> Download Program


[sbscrbr_form]

If you have problem on this blog, you can directly comment or subscribe on website.


 

1564total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

24 Comments

  1. September 17, 2016 - 1:11 pm

    I抦 impressed, I have to say. Actually rarely do I encounter a blog that抯 each educative and entertaining, and let me let you know, you’ve hit the nail on the head. Your idea is excellent; the difficulty is something that not sufficient individuals are speaking intelligently about. I’m very pleased that I stumbled throughout this in my search for something regarding this.

  2. September 18, 2016 - 12:34 am

    After study just a few of the weblog posts on your website now, and I actually like your means of blogging. I bookmarked it to my bookmark website record and will be checking again soon. Pls take a look at my site as effectively and let me know what you think.

  3. September 20, 2016 - 3:47 am

    That is the precise weblog for anybody who needs to seek out out about this topic. You notice a lot its nearly exhausting to argue with you (not that I really would need匟aHa). You positively put a new spin on a topic thats been written about for years. Great stuff, simply great!

  4. September 20, 2016 - 5:45 am

    I discovered your blog web site on google and check a few of your early posts. Continue to maintain up the excellent operate. I just additional up your RSS feed to my MSN Information Reader. Searching for forward to reading more from you in a while!?

  5. September 22, 2016 - 9:19 pm

    I am typically to running a blog and i actually respect your content. The article has actually peaks my interest. I am going to bookmark your web site and hold checking for brand spanking new information.

    • September 23, 2016 - 9:21 am

      I set all basic concepts on this website, so this is very helpful to all beginner in java program
      Thank you

  6. September 23, 2016 - 2:05 am

    That is the right blog for anybody who desires to find out about this topic. You notice so much its nearly laborious to argue with you (not that I actually would need匟aHa). You definitely put a brand new spin on a topic thats been written about for years. Nice stuff, just nice!

    • September 23, 2016 - 9:22 am

      Thank you

  7. September 23, 2016 - 5:28 am

    There are actually a lot of details like that to take into consideration. That may be a great level to carry up. I provide the ideas above as normal inspiration however clearly there are questions like the one you deliver up where a very powerful factor will likely be working in honest good faith. I don?t know if greatest practices have emerged round things like that, however I’m sure that your job is clearly identified as a fair game. Both boys and girls feel the affect of only a moment抯 pleasure, for the remainder of their lives.

  8. September 24, 2016 - 3:16 am

    Spot on with this write-up, I truly think this web site needs much more consideration. I抣l probably be again to read rather more, thanks for that info.

  9. September 24, 2016 - 10:45 pm

    Can I just say what a aid to find somebody who actually knows what theyre speaking about on the internet. You definitely know easy methods to carry a problem to light and make it important. Extra people have to learn this and perceive this aspect of the story. I cant believe youre no more in style because you definitely have the gift.

  10. September 25, 2016 - 6:17 am

    you may have an ideal blog here! would you like to make some invite posts on my blog?

    • September 25, 2016 - 2:19 pm

      definitely i invite post for you blog

  11. September 27, 2016 - 1:26 am

    There’s noticeably a bundle to learn about this. I assume you made certain nice points in features also.

  12. September 28, 2016 - 4:45 pm

    I wish to show some appreciation to the writer for bailing me out of this particular matter. Just after browsing through the the web and seeing views which were not helpful, I was thinking my entire life was done. Being alive minus the strategies to the problems you’ve resolved through your main short article is a crucial case, as well as the ones that would have adversely damaged my entire career if I hadn’t discovered your site. Your personal know-how and kindness in touching a lot of stuff was very useful. I’m not sure what I would have done if I had not come upon such a point like this. I am able to at this time relish my future. Thanks a lot very much for your high quality and result oriented guide. I will not be reluctant to propose the sites to any individual who requires direction about this subject matter.

  13. September 29, 2016 - 2:48 am

    I needed to create you one tiny note in order to give thanks yet again for your personal magnificent tactics you have contributed on this site. It is particularly open-handed of you to provide openly exactly what a lot of folks would have offered for sale for an e-book to end up making some profit for themselves, primarily since you could possibly have done it if you ever considered necessary. These techniques additionally acted to become fantastic way to understand that other individuals have the same desire just like my own to understand much more when considering this condition. I know there are several more enjoyable opportunities ahead for folks who see your site.

  14. October 15, 2016 - 8:40 pm

    It’s remarkable to go to see this site and reading the views
    of all friends concerning this piece of writing, while
    I am also zealous of getting experience.

  15. December 1, 2016 - 10:11 am

    This page really has all the info I wanted about this subject and didn’t know
    who to ask.

  16. December 2, 2016 - 1:28 am

    Good day! Do you use Twitter? I’d like to follow you if that would be ok.
    I’m definitely enjoying your blog and look forward to new posts.

  17. December 7, 2016 - 12:45 am

    Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your webpage?

    My blog site is in the very same niche as yours and my users would genuinely benefit from a lot of the information you provide here.
    Please let me know if this alright with you. Thank you!

  18. December 7, 2016 - 10:23 am

    you are in point of fact a just rigvht webmaster. The web site
    loadxing speed is incredible. It seems hat you are doing any unique trick.
    In addition, The contents are masterwork. you have done a excellent job on this
    matter!

  19. December 18, 2016 - 6:21 am

    I’m really enjoying the design and layout of your blog.

    It’s a very easy on the eyes which makes it much more
    enjoyable for me to come here and visit more often. Did you hire out
    a developer to create your theme? Excellent work!

  20. December 22, 2016 - 12:04 pm

    Valuable info. Lucky me I discovered yourr web site accidentally, and I aam
    stunned why this coincidence did not happened iin advance!
    I bookmarked it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image