-1

Below is my current program

int [] balls = {13, 13, 13}

for(int i = 0; i < 3; i++) 
{
    System.out.println("Remaining balls: " + (i + 1) + " : " + bags[i]);
} 

The output looks like this;

Remaining balls: 13
Remaining balls: 13
Remaining balls: 13

However, I wish for the output to look like this:

Remaining balls: 13, 13, 13

How would I go about this?

I haven't tried many things yet as I'm just starting out.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
JavaNoob
  • 1
  • 1
  • Try Arrays.toString(balls) from the java.util.Arrays package – Melron Nov 16 '22 at 07:19
  • Split it into 3 prints: The initial part, then a loop over the values then the newline outside of the loop – DownloadPizza Nov 16 '22 at 07:21
  • I can't beleave that the output fits to the code. I expect two colons in every line. Please add a [mcve], so that we can run the code – Jens Nov 16 '22 at 07:42

1 Answers1

-2
System.out.println(..)

always adds a new line. That's coded into the method name println

There is also pendants that do not add the extra line add the end of the output:

System.out.print(..)
berse2212
  • 464
  • 5