避免打印最后一个逗号 [英] Avoid printing the last comma

查看:105
本文介绍了避免打印最后一个逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在没有最后一个逗号的情况下打印此循环。我一直在谷歌搜索这个,从我看到的一切似乎过于复杂这么小的问题。当然有一个简单的解决方案,以避免打印最后一个逗号。非常感谢,如果有人可以帮助我,这让我疯了!!!

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 there is an easy solution to avoid printing the last comma. Much appreciated if somebody could help me out, this is driving me insane!!!

例如它从1-10 // 1,2,3,4循环, 5,6,7,8,9,10,<不想要这最后一个逗号

For example it loops from 1-10 // 1,2,3,4,5,6,7,8,9,10, < do not want this last comma

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


推荐答案

我可能会因为这个答案而被石头砸死

I might get stoned to death for this answer

public static void atob(int a,int b) {
  if(a<=b) {
    System.out.println(a);
      for(int i = a+1;i<=b;i++) {
        System.out.println(","+i);
      }
    }
  }
}  

这篇关于避免打印最后一个逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆