Results 1 to 6 of 6
Thread: Help me with this code???
- 10-30-2008, 06:16 PM #1
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
Help me with this code???
in this code i want to compare between 2 integers look and u will understand it
(((((
String o=
JOptionPane.showInputDialog("please enter the kind of operation (+,-,*,/,%");
int plus=Integer.parseInt("+");
int minus=Integer.parseInt("-");
int mult=Integer.parseInt("*");
int divide=Integer.parseInt("/");
int mod=Integer.parseInt("%");
switch(Integer.parseInt(o))
{
case plus: // iwant to compare between plus and o
JOptionPane.showMessageDialog(null, "the value = "+(x+y));
break;
}
)))))))
- 10-30-2008, 06:30 PM #2
why u r trying to compare string and integer?
take (+,-,*,/) as string n then compare .it will work.
dont take plus as int.
- 10-30-2008, 06:36 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 21
- Rep Power
- 0
Not sure what you are doing with int but, equals() can compare objects.
cheers
Ian J
- 10-30-2008, 06:40 PM #4
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
i cannot insert after Switch any string it should be integer and after case must be constant!!!!!!!!!
- 10-30-2008, 07:25 PM #5
I don't understand what your problem is? Can you explain?
if plus is int and o is a String, then you must convert one of them to the same type to be able to compare them. You've done that with the parseInt method. Now they are both int.iwant to compare between plus and o
ints can be compared with the ==, <, > etc operators.
- 10-30-2008, 07:26 PM #6
one easy way to do is like this:
Java Code:String o= JOptionPane.showInputDialog("please enter the kind of operation (1 for +,2 for -,3 for *,4 for /,5 for %)"); switch((Integer.parseInt(o))) { case 1: // iwant to compare between plus and o JOptionPane.showMessageDialog(null, "the value ="+(x+y)); break; }
Similar Threads
-
I need help fixing my code.. or non code?
By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 10:12 PM -
Pls some one to help mi wit this code
By _nik_ in forum New To JavaReplies: 3Last Post: 02-10-2008, 02:02 AM -
help with oop code
By nhlfan in forum New To JavaReplies: 1Last Post: 11-27-2007, 08:21 PM -
Need help with my code.
By stormviper in forum New To JavaReplies: 0Last Post: 07-12-2007, 03:18 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks