Simple Problems... :(

Let's say I have a Long variable named x and a string variable named n
How do I add them together?

ex.:
Long seed;
String n;

seed = seed + n

I know I need something kind of like
seed = seed + Long.getLong(n)
But I can't add and stuff.. :o
thanks
(I don't want a string, I want a long result...)
Nicolas_St_AmourAsked:
Who is Participating?
 
imladrisConnect With a Mentor Commented:

0
 
imladrisCommented:
Presumably you meant for seed to be a primite of type long (rather than an instance of class Long). In that case you could add n to seed by doing:

seed=seed+Long.parseLong(n);

It's kind of the reverse of the toString method in those classes.
0
 
Nicolas_St_AmourAuthor Commented:
If I want to put that value in an array of int, how can I do that?

hmmm... let's say

Array[x] = seed + Long.parselong(n);

How can I make such a statement possible?
0
 
imladrisCommented:
You just need to give it an explicit cast:

int Array[]=new int[50];
int x=2;
Array[x]=(int)(seed+Long.parseLong(n));

This will put the integer portion of "seed+n" into Array[x]. The fractional portion will be lost.
0
All Courses

From novice to tech pro — start learning today.