-1

Hi I'm just new at programming java. So I was just stuck in this example code:

for(int i=0; i < something.length; i++){
    System.out.print(i + " ,");
}

So, basically it will print like this for example 0,1,2,3,.But as you can see there is an extra comma after the number. Is there a way to code this? thanks in advance.

Glen
  • 13
  • 2

1 Answers1

-1

For example

for(int i=0; i < something.length; i++){
    System.out.print(i + i==something.length-1 ? "":" ,");
}
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Thank you so much, it worked. Just made some small adjustments System.out.print(i==something.length-1 ? "":" , "); – Glen Oct 28 '21 at 14:17