double values tend to do that. I recommend having a method round the double value before printing it, so you only print a certain number of digits after the decimal point. A way I usually like to set the number of decimals is to multiply the double by 10^(number of spots after decimal I want), then casting the double to a temporary int value that truncates the decimal point, and then dividing by 10^(number of spots after decimal I want) and storing that in the double value. For example:
double d = 45.6778234; //I only want 2 decimal points after this.
int temp = (int)(10^2*d); //temp will contain 4567.
d = (0.0+temp) / (10^2); //the 0.0 is to be sure that the division is precise. This will store 45.67 in d.
NOTE: I USED THE CARROT NOTATION TO SYMBOLIZE RAISING TO A POWER -- to do this yourself you should look into the Math class or design a method on your own to accomplish this goal. The carrot notation does not work here in java -- that is calculator notation only. You will need to modify the code I have there so that the powers are correctly calculated -- this is just a basic algorithm.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...