Help with java PLEASE PLEASE


OSNN Senior Addict
Im having problems getting my java program to work for my class. I keep getting this error when i try to do a subtraction and i cant figure out why it wont subtract anyway heres the error

operator - cannot be applied to java.lang.String,int
output = "" + (num1 * num2 * (yearString - num3));

for some reason it wont let me subtract :( if you need to see the whole program to figure out the problem ill paste it...its not that long only 20 lines....i think thats all ill need to make the program work. anyway its intro to java class so dont flame me if its a easy fix everyone has to start somewhere. :D



OSNN Senior Addict
Alright well the problem was that the 'yearString' was never actually defined so i had to make a new line

double year = Double.parseDouble(yearString);

to show that yearString was defined as year and then the new equation is

output = "" + (num1 * num2 * (year - num3));

if that even makes sense to anyone....

anyway the program i had to make is to calculate the population on earth when someone puts in a year and it works yay :D now for the extra credit


Folding Team
It makes very much sense if you know how programming works.

yearString is, as it says, a string. It is treated as text. num3 is an integer, a number. If you think about it it makes sense that you can't subtract a number, say 5, from a piece of text. Even if that piece of text happens to be "2003", because the computer can't know this. It might just as well be "Hey there!" - 5, which is just silly. :)