Results 1 to 3 of 3
Thread: Simple calculator
- 09-24-2012, 05:17 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
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:
When ever I type + or -, the error message jumps out automatically instead of calculating the doubles.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(System.in); String x= sc.next(); String w=x; if (w=="+") { System.out.println("Please type in the numbers you would like to conjugate"); Scanner sd=new Scanner(System.in); double y= sd.nextDouble(); double z= sd.nextDouble(); double a= y+z; System.out.println((y+"+"+z+"="+a)); } else if (w=="-") { System.out.println("Please type in the number you would like to substract"); Scanner se=new Scanner(System.in); double y= se.nextDouble(); double z= se.nextDouble(); double a= y-z; System.out.println((y+"-"+z+"="+a)); } else { System.err.println("The mathematical function typed was not recognized. Please type either - or +"); } } }
Thanks for the help!
-IZLast edited by JosAH; 09-24-2012 at 05:19 PM. Reason: added [code] ... [/code] tags
- 09-24-2012, 05:19 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Simple calculator
- 09-24-2012, 05:21 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Help making a very simple calculator?
By sfs in forum New To JavaReplies: 2Last Post: 01-26-2012, 03:59 AM -
Trying to make simple calculator
By Buldogg in forum New To JavaReplies: 1Last Post: 09-18-2011, 01:37 PM -
Simple Calculator
By marksey07 in forum New To JavaReplies: 12Last Post: 01-09-2011, 06:30 AM -
Re: Simple Calculator cont'd
By JavaHater in forum New To JavaReplies: 3Last Post: 01-07-2011, 02:00 AM -
creating a simple calculator
By hobo in forum New To JavaReplies: 4Last Post: 11-09-2009, 03:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks