Results 1 to 3 of 3
  1. #1
    itaiyz97 is offline Member
    Join Date
    Sep 2012
    Rep Power

    Default Simple calculator

    Hey guys! I have been trying to write a simple calculator in java yet I didn't get it to work.
    Here it is:
    Java Code:
     import java.util.*;
     public class FirstClass {
    	 * @param args
    	public static void main(String[] args) {
    		System.out.println("Please choose the mathematical action you would like to preform.");
    		Scanner sc= new Scanner(;
    		String x=;
    		String w=x;
    		if (w=="+") {
    			System.out.println("Please type in the numbers you would like to conjugate");
    			Scanner sd=new Scanner(;
    		    double y= sd.nextDouble();
    		    double z= sd.nextDouble();
    		    double a= y+z;
    		} else if (w=="-") {
    			System.out.println("Please type in the number you would like to substract");
    			Scanner se=new Scanner(;
    		    double y= se.nextDouble();
    		    double z= se.nextDouble();
    		    double a= y-z;
    		} else {
    			System.err.println("The mathematical function typed was not recognized. Please   type either - or +");
    When ever I type + or -, the error message jumps out automatically instead of calculating the doubles.

    Thanks for the help!

    Last edited by JosAH; 09-24-2012 at 05:19 PM. Reason: added [code] ... [/code] tags

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Simple calculator

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Simple calculator

    You can't compare Strings for equality with the == operator, use the equals( ... ) method instead (read the API documentation for the String class).

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Help making a very simple calculator?
    By sfs in forum New To Java
    Replies: 2
    Last Post: 01-26-2012, 03:59 AM
  2. Trying to make simple calculator
    By Buldogg in forum New To Java
    Replies: 1
    Last Post: 09-18-2011, 01:37 PM
  3. Simple Calculator
    By marksey07 in forum New To Java
    Replies: 12
    Last Post: 01-09-2011, 06:30 AM
  4. Re: Simple Calculator cont'd
    By JavaHater in forum New To Java
    Replies: 3
    Last Post: 01-07-2011, 02:00 AM
  5. creating a simple calculator
    By hobo in forum New To Java
    Replies: 4
    Last Post: 11-09-2009, 03:09 AM

Tags for this Thread

Posting Permissions

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