Java: system.out.println concatenating something within a string (really easy question)
I want my output to be Candy[1]. counterInt = 1
But my comp开发者_C百科iler 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+"]");
System.out.println("Candy["+counterInt+"].counterInt="+counterInt);
you should have System.out.println("Candy[" + counterInt + "].counterInt = " + counterInt); to get Candy[1]. counterInt = 1;
You are missing a + after CounterInt.
System.out.println("Candy["+counterInt+"]");
精彩评论