qq_41811552
2018-04-23 13:03
采纳率: 66.7%
浏览 590
已采纳

java+myeclipse 数字输出

问题:有两组范围数字:474~514,783~813两组范围数字(**范围数字会变化**)。
实际范围数字有很多组,且数字范围变化
通过程序处理,输出格式为:

474,475,476,477,478,479,480
481,482,483,484,485,486,487,488,489,490
491,492,493,494,495,496,497,498,499,500
501,502,503,504,505,506,507,508,509,510
511,512,513,514

783,784,785,786,787,788,789,790
791,792,793,794,795,796,797,798,799,800
801,802,803,804,805,806,807,808,809,810
811,812,813

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 遗忘之地12138 2018-04-23 13:28
    已采纳

    public class Test {

    public static void main(String[] args) {
        for (int i = 474; i <= 514; i++) {
            if (i != 514) {
                if(i%10==0){
                    System.out.print(i);
                    System.out.println("");
                }else{
                System.out.print(i + ",");
                }
            } else {
                System.out.print(i);
            }
        }
        System.out.println("");
    
    
    
        for (int i = 783; i <= 813; i++) {
            if (i != 813) {
                if(i%10==0){
                    System.out.print(i);
                    System.out.println("");
                }else{
                System.out.print(i + ",");
                }
            } else {
                System.out.print(i);
            }
        }
    }
    

    }

    点赞 打赏 评论
  • 亦欢 2018-04-23 13:09

    public static void main(string[] args){
    for(int i=474;i<=514;i++){
    if(i!=514){
    system.out.print(i+",")
    }else{
    system.out.print(i)
    }
    }
    system.out.println("");
    for(int i=783;i<=813;i++){
    if(i!=813){
    system.out.print(i+",")
    }else{
    system.out.print(i)
    }
    }
    }

    点赞 打赏 评论
  • qq_18732499 2018-04-23 13:22
    @Test
    public void test() {
        for (int i = 474; i <= 514; i++) {
            if ((i % 10) != 0 && i != 514) {
                System.out.print(i + ",");
    
            } else {
                System.out.println(i);
            }
        }
        for (int i = 783; i <= 813; i++) {
            if ((i % 10) != 0 && i != 813) {
                System.out.print(i + ",");
            } else {
                System.out.println(i);
            }
        }
    }
    //以上代码亲测结果一致
    ![图片说明](https://img-ask.csdn.net/upload/201804/23/1524489760_336425.png)
    
    点赞 打赏 评论

相关推荐 更多相似问题