I have written the following program which takes the duplicates in the doubleArray and adds them to a counter.
Then I wrote a for loop to print out the values in the array going from the smallest value, up by 0.1, to the highest value. Then the program is supposed to put a dollar sign after each number that is represented in the array.
double[] doubleArray = {1.7,1.7,2.0,1.3,1.0};
int count = 0;
Arrays.sort(doubleArray);
for(int i = 0;i<doubleArray.length-1;i++){
for(int j =i+1;j<doubleArray.length;j++){
if (doubleArray[i] == doubleArray[j]) {
count++;
} else {
break;
}
}
}
int finalDub = doubleArray.length;
double min = doubleArray[0];
double max = doubleArray[finalDub - 1];
for (double i = min; i < max+0.1; i += 0.1) {
System.out.printf("%.1f ", i);
System.out.print("$".repeat(count));
System.out.print("\n");
}
But when I run the code, the following gets outputted
1.0 $
1.1 $
1.2 $
1.3 $
1.4 $
1.5 $
1.6 $
1.7 $
1.8 $
1.9 $
2.0 $
When it should be the following because I want it to add the $ only after a double represented in the array, and multiple '$''s for duplicate values.
1.0 $
1.1
1.2
1.3 $
1.4
1.5
1.6
1.7 $$
1.8
1.9
2.0 $
I believe what is happening is the count integer is being set once and never updating. Either way, how can I update my counter logic to represent what I want to be outputted?