• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick Java Question

You can't cast the arrays themselves. Yout need to create another array and cast the individual elements.

You would need something like:
 
damnit...part of the assignment was to write a code with a method set to recieve a float array from a double array from main. And I can't use for loops...it has to all be done recursively. I have all of it written but can't get around this problem.

I guess I could do what you suggested recursively, but are there any more elegant ways around this?
 
Here is a recursive conversion.

The for loop is much more efficient, but this meets the criteria you gave.
 
Originally posted by: CrackaLackaZe
damnit...part of the assignment was to write a code with a method set to recieve a float array from a double array from main. And I can't use for loops...it has to all be done recursively. I have all of it written but can't get around this problem.

I guess I could do what you suggested recursively, but are there any more elegant ways around this?

How about a while loop? 🙂

<-smartass
 
Originally posted by: amdfanboy
Originally posted by: CrackaLackaZe
damnit...part of the assignment was to write a code with a method set to recieve a float array from a double array from main. And I can't use for loops...it has to all be done recursively. I have all of it written but can't get around this problem.

I guess I could do what you suggested recursively, but are there any more elegant ways around this?

How about a while loop? 🙂

<-smartass

He wanted to convert a double[] to a float[], not a float[] to a double[] 😉

<-- smarterass
 
Originally posted by: beyonddc
To get this right, first, you shouldn't use casting.

Take a look at the Java API for - double
http://java.sun.com/j2se/1.4.2...uble.html#floatValue()
You should be using Double.floatValue() to let a Double variable to return you back with a float object.

Sure, if he was dealing with Doubles, but he's not; he's dealing with doubles. Besides which, the implementation of floatValue() casts a double to a float anyways so it wouldn't make any difference.

Edit: p.s. Kilsrat, good to see you answering the noob questions 😉
 
Originally posted by: Kilrsat
Originally posted by: amdfanboy
Originally posted by: CrackaLackaZe
damnit...part of the assignment was to write a code with a method set to recieve a float array from a double array from main. And I can't use for loops...it has to all be done recursively. I have all of it written but can't get around this problem.

I guess I could do what you suggested recursively, but are there any more elegant ways around this?

How about a while loop? 🙂

<-smartass

He wanted to convert a double[] to a float[], not a float[] to a double[] 😉

<-- smarterass

Same thing, right? 😕
 
Back
Top