The Artima Developer Community
Sponsored Link

Java Answers Forum
Whats wrong with this code

2 replies on 1 page. Most recent reply: Apr 23, 2003 3:02 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Courtenay

Posts: 23
Nickname: courtz
Registered: Apr, 2003

Whats wrong with this code Posted: Apr 22, 2003 1:03 PM
Reply to this message Reply
Advertisement
I get an following error with this code:
for(int k = 7999; k > 0; k--){
randomNo = new Double((Math.random() * 5));
list[7999] = new Double(20000.0);
list[k-1] = new Double(list[k] - randomNo);


It has to be a double value.
The error is: operator - cannot be applied tojava.lang.Double,java.lang.Double

Can someone help


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Whats wrong with this code Posted: Apr 22, 2003 3:30 PM
Reply to this message Reply
That is because you have two objects of class java.lang.Double and you cannot perform a minus operation on objects. Convert them to primitive type (double) and you will be fine.

Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: Whats wrong with this code Posted: Apr 23, 2003 3:02 AM
Reply to this message Reply
To follow up on Singh M.'s answer. You can use the doubleValue method.

For example,
list[k-1] = new Double(list[k].doubleValue() - randomNo.doubleValue());


Adam

Flat View: This topic has 2 replies on 1 page
Topic: Address Book Help Previous Topic   Next Topic Topic: Problematic Thread

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use