Samooramad
asked on
convert char to int
Hi experts,
how do I do what I named the title of the question? :)
I know there is something like parseInt or something but I need exact syntax
how do I do what I named the title of the question? :)
I know there is something like parseInt or something but I need exact syntax
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// (if c == '1')
int i = (int)c - '0';
int i = (int)c - '0';
ASKER
what if I dont have a positive value for c to compare it with?
I need something liike:
if myclass.getPosition() == the character converted to integer
I need something liike:
if myclass.getPosition() == the character converted to integer
It depends on how you're treating these chars but say the char is holding a representation of a digit:
char c = '1';
int x = 1;
int y = (int)c - '0';
System.out.println(x == y); // prints true
char c = '1';
int x = 1;
int y = (int)c - '0';
System.out.println(x == y); // prints true
>>what if I dont have a positive value for c to compare it with?
c couldn't hold a negative value. What values do you want it to hold?
c couldn't hold a negative value. What values do you want it to hold?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry got cut off.
yes i meant i do want positive values.. that was a typo
yes i meant i do want positive values.. that was a typo
ASKER
objects dont you need to convert it?
You don't - as my first comment shows
A char is a numeric type that just happens to be able to store 'characters'
ASKER
sorry CEHJ. I didnt understand that was what you meant
thanks
thanks
>>sorry CEHJ. I didnt understand that was what you meant
Yes assignment/comparison address the same type conversion issues
Yes assignment/comparison address the same type conversion issues
ASKER
thanks objects
8-)
ASKER