Results 1 to 3 of 3
  1. #1
    CodeX000 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Calculator Help?

    I cant figure out why I cannot get the right answer when I use this calculator.
    It is meant to be used for division subtraction addition and multiplication
    This is my first java project so sorry if this sloppy :)



    import java.util.Scanner;

    public class Calculator {

    public static void main(String args[]){
    Scanner calc = new Scanner(System.in);

    int one;
    int two;
    int answer;

    System.out.println("First Number?");
    one = calc.nextInt();

    System.out.println("Second Number?");
    two = calc.nextInt();

    int add_sub;
    System.out.println("Press 1 for Add, 2 for Sub, 3 for Mult, or 4 for Divide.");
    add_sub = calc.nextInt();

    if (add_sub == 1);{
    answer = one + two;
    }
    if (add_sub == 2);{
    answer = one - two;
    }
    if (add_sub == 3);{
    answer = one * two;
    }
    if (add_sub == 4);{
    answer = one / two;
    }
    System.out.println("Here is the answer: " + answer);

    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Calculator Help?

    Quote Originally Posted by CodeX000 View Post
    Java Code:
    		if (add_sub == 1);{
    
    		if (add_sub == 2);{
    
    		if (add_sub == 3);{
    
    		if (add_sub == 4);{
    What are these semicolons doing there? Better to remove them ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    CodeX000 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

Similar Threads

  1. need some help with my calculator
    By Tooks1 in forum New To Java
    Replies: 0
    Last Post: 02-13-2013, 06:38 PM
  2. Calculator
    By Elviii in forum New To Java
    Replies: 6
    Last Post: 01-06-2013, 02:43 AM
  3. BMI calculator
    By snustad in forum New To Java
    Replies: 4
    Last Post: 11-29-2012, 09:08 PM
  4. calculator
    By rithish in forum AWT / Swing
    Replies: 10
    Last Post: 04-25-2011, 11:24 PM
  5. help with calculator
    By kalibballer in forum New To Java
    Replies: 8
    Last Post: 04-01-2009, 12:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •