黑马程序员技术交流社区

标题: 发表一个程序看是否有错 [打印本页]

作者: 天火传说    时间: 2015-6-1 21:22
标题: 发表一个程序看是否有错
package com.itheima;
/*编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72*/
public class Test6 {

       
        public static void main(String[] args) {
                int i;
                for(i=1;i<=100;i++)
                {if( i%10!=7&& i/10!=7)
                        System.out.printf("%d  ",i);
                        }

        }

}

作者: mnxnm    时间: 2015-6-2 00:17
  1. /**
  2. *
  3. * 编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
  4. *
  5. * @author sman@mnxnm.com
  6. *
  7. */
  8. public class 打印不包含特定数字的整数 {

  9.         public static void main(String[] args) {
  10.                
  11.                 int numMax = 100, numOut = 7;
  12.                
  13.                 String strOut = String.valueOf(numOut);
  14.                 for (int i = 1; i <= numMax; i++) {
  15.                         String str = Integer.toString(i);
  16.                         if (!str.contains(strOut)) {
  17.                                 System.out.println(i + " ");
  18.                         }
  19.                 }
  20.         }
  21. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2