java programming question #2

VRoOMdesigns

Guest
Aug 2, 2000
806
0
0
how do you convert a String into an int? My string is composed entirely of numbers say 505, how do I turn this into an int value?

thanks.
 

Cattlegod

Diamond Member
May 22, 2001
8,687
1
0
can't remember the exact command, don't have my book handy. something like
int x = string.parseInt();

or something
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
dont know the java answer, but this is it in perl:
$string = "505";
$string++;

print "$string";

<--- prints "506"

Perl rocks

Sorry, but that doesn't help you too much///
 

VRoOMdesigns

Guest
Aug 2, 2000
806
0
0
ya it's for a class. i learned c++ years ago, and my mind still operates in that syntax...

oh to cin and cout.. << >>
 

BlackFalcon

Senior member
Apr 6, 2000
285
0
0
Sun's online Java API is a very good thing. If you are going to use Jave much learn to use it. It will save tons of time with questions like this.
The answer.
(It's in Integer not String).
 

shikhan

Senior member
Mar 15, 2001
834
0
71


<< Java is suck. Learn a decent programming language like C++. >>



Personally, i think java is a helluva lot more versitile and powerful than C++... Plus, it was built as an OO language unlike C++.... I'm in no way bashing C++ as its one of my favorite languages to program in, but Java is as good if not better....

as to answer your question VroOMdesigns, Cattlegod is right. The parseInt function is exactly what your looking for.
 

DocZaius

Senior member
Oct 7, 2000
457
0
0
Java owns, C++ is teh suck.

VRoOMdesigns, to answer your question.

String str = "123";
int i;

i = Integer.parseInt(str);
 

VRoOMdesigns

Guest
Aug 2, 2000
806
0
0
nevermind. i just got it.

if any of you want to know it's :

Integer temp = Integer.decode(String s);
int x = temp.intValue();

but now i'm getting NumberFormatExceptions!? WTF?
 

VRoOMdesigns

Guest
Aug 2, 2000
806
0
0
bah i'm doing something wrong. ignore me. i'll figure it out.

thanks for the link to the documentation btw, i was looking in the String class...
 

Scootin159

Diamond Member
Apr 17, 2001
3,650
0
76
int intvalue;
String mystring = new String("123");

intvalue = mystring.intValue();


I *believe* that is correct, but I'm not sure. Look up the java documentation on the sun website for a complete listing of the meathods of the String class. LOTS of useful info there.
 

KEV1N

Platinum Member
Jan 15, 2000
2,932
1
0
One main reason for Java not sucking is the strong typing. No more type mismatch, baby!
 

BearX00

Senior member
Nov 28, 2000
208
0
0
You guys cant diss java like that, it is a really good tool to know and use. Ive been using it for about two years now for various classes, and its ease of use is amazing. I'm not a no skilled programmer, i am in school for a cs degree right now. 4th year. I love C and C++ i use them all the time, but for projects i do for class, where time is limited and the projects are complicated, its the best tool, beats C/C++ for most things because of the fact of its extensive class base and GREAT documentation. At work we use C++ and i wouldnt have it any other way but java is cool.
 

Scootin159

Diamond Member
Apr 17, 2001
3,650
0
76


<< You guys cant diss java like that, it is a really good tool to know and use. Ive been using it for about two years now for various classes, and its ease of use is amazing. I'm not a no skilled programmer, i am in school for a cs degree right now. 4th year. I love C and C++ i use them all the time, but for projects i do for class, where time is limited and the projects are complicated, its the best tool, beats C/C++ for most things because of the fact of its extensive class base and GREAT documentation. At work we use C++ and i wouldnt have it any other way but java is cool. >>



I'm not dismissing JAVA at all, in fact it's probably my favorite language, but I just wish it weren't case sensitive.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |