How would you convert a string that is loaded from a txt file into a integer so it can be used for calculations?
Converting types
Collapse
X
-
Tags: None
-
Originally posted by javatech007How would you convert a string that is loaded from a txt file into a integer so it can be used for calculations? -
alternatively you could use a scanner object to read from the file and use the function of parseInt to convert from string to integer and use the value for calculations.
i.e
Scanner inFile = new Scanner(new FileReader("fil ename"));
String x = inFile.next();
int x2 = Integer.parseIn t(x);
then int sqr = Math.pow(x2,2); //this is just an example of a calculation you can do after converting
Note: read more on the Scanner class API and Integer to understand what i just wrote.
hope its easier to understand and helps you.
good luckComment
-
Originally posted by rodeovalString intValue;
Integer integer = new Integer(intValu e);
int value = integer.intValu e();
[CODE=Java]int value = Integer.parseIn t(str);[/CODE]Comment
Comment