开发者

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+"]");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜