I want to input the W into the int array. How can i do that? Sorry for the lousy question or english.
public void setX (int Y , double W)
{
array[Y] = W;
}
If you're happy to truncate towards 0 - and get int.MIN_VALUE
or int.MAX_VALUE
if the value is out of the range of int
- you can just cast:
array[Y] = (int) W;
If you're not happy with those caveats, you should re-evaluate your design - think about what you want to happen, e.g. if W
is 15.25
. If you need to preserve all the original information, you should use a double[]
rather than an int[]
.
(You should also revisit your parameter names, if those are your real names. Read up on Java naming conventions.)
See more on this question at Stackoverflow