Basic Java Calculator using Switch Case Statement


Java Code: Basic Calculator using Switch Case

Posted on

Sunday, June 10, 2012

15 Comments
  1. Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
    Java training in Rajaji nagar | Java training in Kalyan nagar

    Java training in Kalyan nagar | Java training in Jaya nagar

    ReplyDelete
  2. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
    Data Science Training in Indira nagar | Data Science Training in btmlayout

    Python Training in Kalyan nagar | Data Science training in Indira nagar

    Data Science Training in Marathahalli | Data Science Training in BTM Layout

    ReplyDelete
  3. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any python Related information please visit our website Python Training In Pune page!

    ReplyDelete
  4. Irrespective of rankings, this will help in huge traffic generation, on your website, over time and, in turn,will steadily increase the number of potential customers for your products and services.

    java training in chennai

    java training in velachery

    aws training in chennai

    aws training in velachery

    python training in chennai

    python training in velachery

    selenium training in chennai

    selenium training in velachery

    ReplyDelete
  5. import java.util.Scanner;

    class basicalc{
    public static void public static void main (String[] args)
    {
    Scanner user_input = Scanner(System.in);
    double fnum,snum,ans;
    int ch;

    System.out.println("1. Addition");
    System.out.println("2. Substraction");
    System.out.println("3. Multiplication");
    System.out.println("4. Division");
    System.out.println("5. Choose you operator: ");
    ch = user_input.nextInt();
    System.out.println(" ");

    switch (ch){
    case 1:
    System.out.println("You choose Addition");
    System.out.print("Enter first num : ");
    fnum = user_input.nextDouble();

    System.out.print("Enter second num : ");
    snum = user_input.nextDouble();

    ans = fnum+snum;
    System.out.println("Enswer is : " + ans);
    break;

    case 2:
    System.out.println("You choose Substraction");
    System.out.print("Enter first num : ");
    fnum = user_input.nextDouble();

    System.out.print("Enter second num : ");
    snum = user_input.nextDouble();

    ans = fnum-snum;
    System.out.println("Enswer is : " + ans);
    break;

    case 3:
    System.out.println("You choose Multiplication");
    System.out.print("Enter first num : ");
    fnum = user_input.nextDouble();

    System.out.print("Enter second num : ");
    snum = user_input.nextDouble();

    ans = fnum*snum;
    System.out.println("Enswer is : " + ans);
    break;

    case 4:
    System.out.println("You choose Division");
    System.out.print("Enter first num : ");
    fnum = user_input.nextDouble();

    System.out.print("Enter second num : ");
    snum = user_input.nextDouble();

    ans = fnum/snum;
    System.out.println("Enswer is : " + ans);
    break;

    default:
    System.out.println("You can choose from number 1 to 4 only");
    }
    }
    }

    ReplyDelete
    Replies
    1. public static void public static void main (String[] args)-------this is wrong.

      public static void maim (String[] args)

      Delete
  6. break;--------- in end.

    ReplyDelete