家庭作业:求0-200以内所有能被7整除但不能被4整除.按每行6个打印.我在做作业时.发现按每行六个打印就肯定不能用println了,要用print.每个数字间要空格或者用别的符号分开吧.我却不会输出空格,也不会输出其他符号.请各位朋友帮忙.
还有能帮我想下怎样才能每行6个打印吗?

解决方案 »

  1.   

    for(int i = 7, j = 0; i < 200; ++i) {
      if(i % 7 == 0 && i % 4 != 0) {
        ++j;
        System.out.print(i);
        if(j % 6 == 0) System.out.print('\n');
        else System.out.print(' ');
      }
    }
      

  2.   

    我喜欢这样写:
    int count = 0;
    for(int i = 7; i <= 200; i += 7){
      if(int i % 4 != 0)
        System.out.printf("%-4d",i);
      if(++count % 6 == 0)
        System.out.println();
    }
      

  3.   

    郁闷……
    写少了一句话
    int count = 0;
    for(int i = 7; i <= 200; i += 7){
      if(int i % 4 != 0)
        System.out.printf("%-4d",i);
      else
        continue;
      if(++count % 6 == 0)
        System.out.println();
    }