[Solved] How to print array index number?


Though your question is not very clear, it seems you just want o print the array index with contents, in that case you can follow the below code:

for(int i=0;i<fruit.length;i++){
    System.out.println((i+1)+"."+fruit[i]);
}

Or if you want the number to store the index in the array contents, then you can go with:

for(int i=0;i<fruit.length;i++)
    {
        System.out.print("Fruit number "+ Math.addExact(i, 1)+ ": ");
        fruit[i] = (i+1)+"."+scan.nextLine();
    }

Hope it helps.

solved How to print array index number?