• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

java programming question #2

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.
 
can't remember the exact command, don't have my book handy. something like
int x = string.parseInt();

or something
 
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///
 
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).
 


<< 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.
 
Java owns, C++ is teh suck. 😀

VRoOMdesigns, to answer your question.

String str = "123";
int i;

i = Integer.parseInt(str);
 
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?
 
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...
 
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.
 
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.
 


<< 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.
 
Back
Top