Results 1 to 4 of 4
Thread: Error: unexpected type
- 07-18-2007, 04:55 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 35
- Rep Power
- 0
Error: unexpected type
Hi, I have tried every way I could think to correct this problem. This is the last of 13 errors I had to find debugging this assignment.
after compiling it, the error message said:Java Code:interest = annualInterest 12;
the declaring variables areJava Code:possible loss of precision found: double required: int
int price, downPayment, tradeIn, months, loanAmt, interest;
double annualInterest, payment;
under conversions there is this:
under calculations the line of code isJava Code:annualInterest =Double.parseDouble(inputAnnualInterest);
I tried putting "/" in front of 12, got an error. Tried putting parantheses aroundJava Code:interest = annualInterest 12;
(annualInterest 12) got an error. How to get int when there is a double. I determined from declared variable annualInterest was the double. So here is what I tried next:
got an error backJava Code:interest = (double = (annualInterest / 12));
Java Code:unexpected type required: variable found : class interest = (double = (annualInterest / 12)); ^(under the d in double) 1 error
My understanding is everything in the ( ) has to equate to an int and not double...since interest is an int. Must be close because the error message no longer says found: double required: int. It just says found:class required variable.
Maybe someone can clarify my understanding.
Thanks
- 08-07-2007, 05:41 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Think to yourself what are you DOING with interest. How do you get it. You weren't really doing anything to it. The interest might be better off as a double. In the future post all of your code.Java Code:interest = annualInterest / 12;
Greetings.
- 02-05-2010, 08:51 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
This is called type casting, and if interest is of type double it's:
interest = (double)(annualInterest/12);
- 02-05-2010, 09:54 PM #4
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
agreed with barney. If i am correct int uses 32 bits. Double uses double-precision 64 bits. You cant put a 64 bit value into 32, so the compiler shouts at you. Double is the largest datatype used by java.
This can give you more information if needed: Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
Good luck
Similar Threads
-
Error: invalid method declaration; return type required
By silvia in forum AWT / SwingReplies: 3Last Post: 06-05-2010, 08:05 PM -
Putting your own type in a Set
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:32 PM -
Type Casting Help
By rhm54 in forum New To JavaReplies: 2Last Post: 02-07-2008, 12:06 PM -
An unexpected jumper bug on my IO code?
By cruxblack in forum New To JavaReplies: 7Last Post: 07-29-2007, 08:24 AM -
The return type
By Marcus in forum New To JavaReplies: 1Last Post: 07-05-2007, 06:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks