forming negative numbers
What would be the best way to form negative numbers from a string "-" and a number?
I can convert the number to a string, so I'd have say "-5", but that's a string and not really the number -5.
Is there a way to tell Java that it's a number with a negative value?
But why do you want to tell java that its a negative number.
For jvm a number is a number, no matter positive or negative. jvm is not bothered till the time number is valid and within range.
It would be your program, which needs to differentiate between positive and negative numbers. A simple check of lessThan and greaterThan Zero(0) can be used to differentiate between numbers.
I am not sure, but are you looking for
int i = Integer.parseInt("-5")
Oh ok, so if I had a string "-5" and used parseInt, it would turn it into an integer of -5?
Hm what's the quickest way to find this out?
Originally Posted by TopNFalvors