How to print a double array?

I need to print this double array, but I continue to get an error in the last line with an “index”, and it says “cannot convert double to int”.

double[] i1 = new double[] {0.15, 0.875, 0.375};

Arrays.sort(i1);
System.out.print("1st array : ");

for(double index=0; index < i1.length ; index++)
    System.out.print("  "  + i1[index]);
+4
source share
2 answers

The array doublestill has indexes int(like any type of array), so it indexshould be int:

for(int index=0; index < i1.length ; index++)
    System.out.print("  "  + i1[index]);
+3
source

Alternatively , Arrays.toString (array) .replaceAll (",", "YourFavoriteSeparator")

0
source

Source: https://habr.com/ru/post/1606677/


All Articles