Remove last separator from print statement

前端 未结 6 669
情深已故
情深已故 2021-01-26 09:34

Here\'s a method for sorting an integer array. How can I remove the last separator form the output?

public void Sort(int[] sort) {
        for (int a:sort) {
            


        
6条回答
  •  粉色の甜心
    2021-01-26 09:48

    Easily can do like below:

        for (int i = 0; i < sort.length; i++) {
           System.out.print(i < sort.length-1 ?sort[i]+", " : sort[i]+"");
        }
    

提交回复
热议问题