Java: System. Out. Println Concatenating Something Within a String (Really Easy Question)
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...
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.
5 Answers
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+"]");