Remove last separator from print statement

前端 未结 6 735
情深已故
情深已故 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 10:03

    I think this can fix the problem just try it.

    public static void sort(int[] sort) {
        for (int a:sort) {
            if(a==sort[sort.length-1])
                System.out.println(a);
            else
                System.out.print(a+ ", ");
        }
    

提交回复
热议问题