views:

76

answers:

5

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.

+3  A: 

You must put a + after counterInt:

System.out.println("Candy["+counterInt+"]");
True Soft
Thanks a lot, that did the trick
Kevin Duke
+1  A: 

you should have System.out.println("Candy[" + counterInt + "].counterInt = " + counterInt); to get Candy[1]. counterInt = 1;

GK
A: 

You are missing a + after CounterInt.

phisch
A: 
System.out.println("Candy["+counterInt+"]");
JRL
+1  A: 
System.out.println("Candy["+counterInt+"].counterInt="+counterInt);
Neeraj