String j is a random number
String g is another random number.
Here i am trying to subtract one random number from another (j-g)
From doing this i am getting an error of:
Any help?
Carey Brown wrote:At line 55 you have
Here 'j' is defined as a String. The calling of parseInt() here will always thrown an exception because j has been initialized to null.
'j' is local to this block of code and would not be visible outside of the block.
Bod McLeon wrote:
But now I have an error of:
Operator '-' cannot be applied to 'java.lang.string','java.lang.string'.
(This is after making it into one code block and needing to finalise the variable 'j')
Henry Wong wrote:
Bod McLeon wrote:
But now I have an error of:
Operator '-' cannot be applied to 'java.lang.string','java.lang.string'.
(This is after making it into one code block and needing to finalise the variable 'j')
The "-" operator can't be applied to two strings. There is no such a thing as "subtracting strings". What are you trying to do exactly?
Henry
fred rosenberger wrote:I locked your other thread where you posed this question. Please don't post the same question more than once.
Hi Bod, welcome to the Ranch. I'll mention some other aspects.
Liutauras Vilda wrote:
Hi Bod, welcome to the Ranch. I'll mention some other aspects.
...
where i need 'Private' or an instance variable
Norm Radder wrote:
where i need 'Private' or an instance variable
I would not worry too much about using private in your code. Wait until the time comes that you need it. It's not too important with beginning programs.
Define a variable as an instance variable (as opposed to one that is local to a method) when the code needs access to the variable from more than one method.