Java String to Int?

# Thread: Java String to Int?

1. ## Java String to Int?

OK, So I am working on a calculator that takes in LaTeX code and spits out step by step instructions on how to solve the problem. Right now I am working on the sigma series, but I am having some difficulty trying to get the value of a String in terms of integers.

For example a hypothetical input would be "\sum^{5}_{i=0}i"
I need to take it apart, the create a "for"-loop that runs while i&lt;=5 and the solution is "0+1+2+3+4+5". However, the problem is taking the "^{5}" and making it into an integer value.

Same goes for the "_{i=0}" clause. And I guess the same goes for the summation term.

How would I do this?

2. If you can get it down to just the integer within that string you want you can use:
Integer.parseInt(stringcontainingonlyinteger);
I'm not sure if that's what you want or if you want to know how to actually break it down to just the integer.

3. That's exactly what I was looking for, thanks! I'll look this up to see how it is used...

4. Code:
public class test {
public static void main(String[] args){
int getInt=0;
String numString="454"; // The String to convert
try{
getInt = Integer.parseInt(numString); // Change the String to an int
System.out.println(getInt); // Will output the number
catch(NumberFormatException nfex){
}
}
}
Or something like that. The try-catch bit isn't needed, but it makes things smoother in the long run if something goes wrong.

enmand

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•