Forums Register Login

Stuck in programming a simple calculator

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Pay attention! Tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 701 times.
Similar Threads
searching for specific data in a text file
Need help with arrays
Logical Error :/
help with loop
user input
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:27:29.