This is a Basic Java Calculator using If..ElseIf..Else Statement.






Basic Calculator using If..ElseIf..Else

Posted on

Sunday, June 10, 2012

17 Comments
  1. i m finding a little bit problem in the last codding .
    @@@@@

    import java.util.scanner;
    class calculator
    {
    public static void main(Strng args[])
    {
    Scanner user_input = new Scanner(System.in);
    double ch;
    int ch;

    System.out.println("1. addition");
    System.out.println("2. subtratcion");
    System.out.println("3. multiplication");
    System.out.println("4. division");
    System.out.println("choose your operator:");
    ch = user_input.nextInt(" ");

    if (ch ==1)
    {
    System.out.println("you chose addition ");
    System.out.println("entre the first no;");
    x = user_input.nextDouble();

    System.out.println("entre the second no");
    y = user_input.nextDouble();

    z = x+y;
    System.out.println(z);
    }
    else if (ch==2)
    {
    System.out.println("you chose subtraction");
    System.out.println("entre first no");
    x = user_input.nextdouble();

    System.out.println("entre the second no");
    y = user_input.nextDouble();

    z = x-y;
    System.out.println(z);
    }
    else if(ch==3);
    {
    System.out.println("your operation is multiplication");
    System.out.println("entre the first no");
    x = user_input.nextDouble();

    System.out.println("entre the second no");
    y = user_input.nextDouble();

    z = x*y;
    System.out.println(z);
    }
    else if(ch==4);
    {
    System.out.println("your operation is division");
    System.out.println("entre the first no");
    x = user_input.nextDouble();

    System.out.println("entre the second no");
    y = user_input.nextDouble();

    z = x/y;
    System.out.println(z);
    }
    else
    {
    System.out.println("you can choose only 1--4 ");
    }
    }
    }

    ReplyDelete
  2. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.
    python training in OMR
    python training in Bangalore
    python training in rajajinagar
    Python training in btm
    Python training in usa

    ReplyDelete
  3. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  4. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.

    Java training in Tambaram | Java training in Velachery

    Java training in Omr | Oracle training in Chennai

    ReplyDelete
  5. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.


    Best PHP Training Institute in Chennai|PHP Course in chennai

    Best .Net Training Institute in Chennai
    Dotnet Training in Chennai
    Dotnet Training in Chennai
    Dotnet Training in Chennai

    ReplyDelete
  6. Amazing code... I really need it 🤗

    ReplyDelete
  7. Python Training in Chennai | Infycle Technologies


    Like this or that software is best nowadays, Hence python training institutes in Chennai are grooming big. Here, Infycle leading in the top position. Because of good & Friendly trainers, Hi-Fi environment, 200% practical classes, pre-interview session. Along with coaching, they give new confidence to students. Via Infycle, you can able to mold your career in a good way. For more details contact Infycle at 7502633633.

    Best python trainig in Chennai

    ReplyDelete