Strings and ints

J

JS

Hi all,
Is there anyway to read a number in from a file or similar as a String and
use it as an int variable i.e.

String s = "123";
int i = s;

The above code doesnt work because of the different types so are there any
methods anyone knows of to manage this.
Thanks in advance
JS
 
T

Thomas Weidenfeller

JS said:
Hi all,
Is there anyway to read a number in from a file or similar as a String and
use it as an int variable i.e.

What does your textbook say?
String s = "123";
int i = s;

The above code doesnt work because of the different types so are there any
methods anyone knows of to manage this.

Look at the documentation of the Integer class and consider asking
beginner's questions in comp.lang.java.help.

/Thomas
 
T

Tim Slattery

JS said:
Hi all,
Is there anyway to read a number in from a file or similar as a String and
use it as an int variable i.e.

String s = "123";
int i = s;

int i = Integer.parseInt(s);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top