Avoid printing the last comma

前端 未结 13 548
无人及你
无人及你 2020-12-03 14:58

I\'m trying to print this loop without the last comma. I\'ve been Googling about this and from what i\'ve seen everything seems overcomplex for such a small problem. Surely

13条回答
  •  自闭症患者
    2020-12-03 15:47

    public static void atob(int a, int b) {
        if (a < b) {
            System.out.print(a);
            while (a < b) {
                a++;
                System.out.print("," + a);
            }
        }
    }
    

    When called with

    atob(0,10);
    

    Will give the output

    0,1,2,3,4,5,6,7,8,9,10

提交回复
热议问题