working on a calculator program where i will need to split string of numbers into 2 longs. trying to use Integer.parseInt inside for loop. please let me know what i am doing wrong
int half;
half = inputString1.length()/2;
System.out.println(half);
for(int i = 0; i < half; i++)
{
input3 = Integer.parseInt(inputString1.charAt(i));
}
for(int i = half; i < inputString1.length(); i++)
{
input4 = Integer.parseInt(inputString1.charAt(i));
}
that code throws error. when i try to use Integer.valueOf or Integer.getValue, it returns the ascii value
2 replies to this topic
#1
Posted 03 December 2010 - 11:08 AM
|
|
|
#2
Posted 03 December 2010 - 11:15 AM
What was the error?
possibly Integer.parseInt() does not work with chars so try
This will turn the char into a String
possibly Integer.parseInt() does not work with chars so try
input3 = Integer.parseInt(inputString1.charAt(i) [COLOR="red"][B]+ ""[/B][/COLOR]);
This will turn the char into a String
#3
Posted 03 December 2010 - 11:21 AM
thank you. worked perfectly
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









