The problem is that num1 and num2 are doubles which sum up to a double. The compiler is concerned what to do about the decimal part of that double since it can't be put in an integer. You can solve it by making anser of type double or casting
Jeanne's suggestion will get rid of the error and allow your code to compile, but before you do that, you need to ask youself why num1 and num2 are doubles while answer is an int. Do you have a good reason for starting with two doubles, adding them, and then dropping the fractional part? Or would it make more sense to make num1 and num2 ints, or to make answer a double?
Also you are asking the user to enter a number but not bothering to store it anywhere and then you are asking them to enter a letter and are trying to convert it to a double.
You should always check the value returned by the input dialog before using it in case the user cancelled the dialog, in which case the input dialog will return null.
Joined: Aug 07, 2007
And another thing, why do you have double variables called S, A, M & D.
You should always give variables meaningful names and use the Java naming conventions (variable names start with a lower case letter).
What do these variables do? you never assign values to them but use them in a comparison with choice and character.
It looks like you have become confused over how to test for which math operator the user wants to use and have ended up combining multiple solutions. I suggest you sit down with a pen and paper and write out in words how you want to solve the problem before trying to code it.
tried this and got 1 error
Are you sure, there are loads of compilations errors in this code.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com