Jump to content

Integer.parseInt not working inside loop

- - - - -

  • Please log in to reply
2 replies to this topic

#1
netopalis45

netopalis45

    Newbie

  • Members
  • Pip
  • 2 posts
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
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
What was the error?
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
netopalis45

netopalis45

    Newbie

  • Members
  • Pip
  • 2 posts
thank you. worked perfectly




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users