Forums Register Login

Switch Case Problem

+Pie Number of slices to send: Send
i had written a small code for calculator using switch case & getting the values at runtime. But multiplication is not happening.


what can be the solution for it?
+Pie Number of slices to send: Send
Welcome to JavaRanch, Mohsin

Please UseAMeaningfulSubjectLine when you post anything on JavaRanch. Also please UseCodeTags when you post a source code - It's unnecessarily hard to read the code otherwise. I've edited your post accordingly.

Getting into your question, what did you mean by "multiplication is not happening.", are you getting any exception, incorrect result, or something else? Please TellTheDetails.
+Pie Number of slices to send: Send
Hi mohsin

it seems that reading from consol as string * loss his identity. so convert in chararray and then use the first position value as operation.
+Pie Number of slices to send: Send
Thanks Devaka,

"Multiplication not happening" - by that i mean, its not giving any error but it is taking the program flow to default statement. Therefore unable to get multiplication result.



calc.jpg
Output
[Thumbnail for calc.jpg]
+Pie Number of slices to send: Send
I suggest you find out what the JVM thinks args[2].charAt(0) is . . .

Insert this line before the switch block and see what it prints.
System.out.printf("args[2].charAt(0) = %c%n", args[2].charAt(0)); //test code
1
+Pie Number of slices to send: Send
put a print statement like this,


and see the result. if you don't quote your asterix "*" when you pass in your arguments, it will do a shell expansion.
so quote your "*" when you pass in as argument
+Pie Number of slices to send: Send
@Jave - your name is almost Java & your post worked for me, Thanks
@Campbell Ritchie - Thanks
@Ravi - Thanks for your reply...

enJoy Guys!!
+Pie Number of slices to send: Send
You're welcome
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4364 times.
Similar Threads
Swap function in java
The method showMessageDialog(Component, Object) in the type JOptionPane is not applic
[HOMEWORK] Please need help with java project
Large Numbers
How to get the sign bit?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:25:36.