• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck in programming a simple calculator  RSS feed

 
Jonathan Vazquez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im simpy programming a simple calculator like every new java beginner. However, im trying to get a bit more detail and use the month of java knowledge i know. I created


i want the user to be able to input they're desired mathematical equation


That was the closest i could get to a char. However, when i try to implement a switch Statement because of its simplicity i get and error.


apperantly i cannot use a String on a switch statement. I do recon i can use a char but how will i be able to when i declared the mathEqua variable a String for the user input.

Please anything is well appreciated (Im comming from another forum that has a dead java beginner section). Im looking to use a more cleaner code based method not the whole "Press the integer 1 for addition, etc." . My goal is to provide this application later with a User Interface (GUI) in which i can use in my computer.

Im also looking into adding the:

to provide with mor mathematical expression rather than the simple +, /, -, and *.

thank you
-AndreeU
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use string in switch statements only in Java 7 and later. If you are using a version of Java that is older than 7 then you can only use primitives. Read this
 
Jonathan Vazquez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i understand now what i did wrong. I simply didnt make the case the way it was suppose to. Thank you for the quick reply and fast aid

Thank YOu

*PROBLEM SOLVED *

Merci Beaucoup
 
akshay nayak
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings are supported in switch statements from java 7 onwards, so if you have the JDK 7 installed on the machine it should not be a problem.

If however you are using any version of java before v7, you can make the following changes to your program:



You can then use the char variable obtained above in your switch statement.

Hope that helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!