I want my output to be Candy[1]. counterInt = 1
But my compiler isn't taking this code:
System.out.println("Candy["+counterInt"]");
What can I do to have this variable appear within the string Candy[]?
Candy[] is not an array, it's a string.
I want my output to be Candy[1]. counterInt = 1
But my compiler isn't taking this code:
System.out.println("Candy["+counterInt"]");
What can I do to have this variable appear within the string Candy[]?
Candy[] is not an array, it's a string.
You must put a + after counterInt:
System.out.println("Candy["+counterInt+"]");
you should have System.out.println("Candy[" + counterInt + "].counterInt = " + counterInt); to get Candy[1]. counterInt = 1;
System.out.println("Candy["+counterInt+"].counterInt="+counterInt);