Java arrays. I need to compute the \'counterIndex\' from a double to an integer
ID: 3793200 • Letter: J
Question
Java arrays.
I need to compute the 'counterIndex' from a double to an integer index. My data file has decimals in it, so I used double rather than int when needed, but I don't know how to get it to convert back to int for the output.
Here is my code:
public static int fillArray (trackData tracks, int nTracks, int fields, double max, double min) double range max-min: double width (int) (range/ 10.0) +1: double counter Index for (int i 0: iknTracks i++) counter Index tracks [i]. length-min; terIndex Widt Coun fields [counter Index return width:Explanation / Answer
The best way to convert a double value into int is by initialising another variable, say i, of data type int and do the following :-
Double counterIndex;
Integer i = counterIndex.intValue();
OR
double counterIndex;
int i = (int) counterIndex;
In your case follow the second approach as you have used the data type as double not the class Double.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.