File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Switch Case Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch Case Problem" Watch "Switch Case Problem" New topic
Author

Switch Case Problem

Mohsin Shaikh
Greenhorn

Joined: Mar 27, 2009
Posts: 3
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?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3018
    
  35

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.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Ravi Shankar Kumar
Ranch Hand

Joined: Aug 08, 2008
Posts: 30
    
    1

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.


Ravi Shankar Kumar
SCJP 1.5, (Following-OCWCD)
Mohsin Shaikh
Greenhorn

Joined: Mar 27, 2009
Posts: 3
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.






[Thumbnail for calc.jpg]

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
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
Kurosaki Ichigo
Greenhorn

Joined: Dec 31, 2010
Posts: 10
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
Mohsin Shaikh
Greenhorn

Joined: Mar 27, 2009
Posts: 3
@Jave - your name is almost Java & your post worked for me, Thanks
@Campbell Ritchie - Thanks
@Ravi - Thanks for your reply...

enJoy Guys!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Switch Case Problem
 
Similar Threads
Swap function in java
The method showMessageDialog(Component, Object) in the type JOptionPane is not applic
Large Numbers
How to get the sign bit?
[HOMEWORK] Please need help with java project