A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 任黎明 中级黑马   /  2014-6-5 22:44  /  1883 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.itheima;
/*
* @author 任黎明
* 8、 编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
* */
public class Test8
{
        public static void main(String[] args)
        {
                for(int x=1;x<=100;x++)
                {
                        if(!(x%10==7||((x-x%10)/10)==7))
                        {
                                if(x<100)
                                        System.out.print(x+",");
                                else
                                        System.out.print(x);
                        }
                }
        }
}


5 个回复

正序浏览
支持一下子
回复 使用道具 举报
本帖最后由 相濡、彼岸 于 2014-6-7 20:35 编辑

class Demo1
{
      public static void main(String[] args)
      {
              int x=0;
           while(x<100)
           {                                                                   //不知道这样行不?呵呵!
                    x++;
              if(!String.valueOf(x).contains("7"))
                    System.out.println(x);
              else
                    continue;
            }
      }
}
回复 使用道具 举报
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
回复 使用道具 举报
我同样问题的回答
  1. package com.itheima;

  2. import java.util.ArrayList;

  3. /**
  4. *7、 编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
  5. * @author qingguiyu
  6. *
  7. */
  8. public class Test7 {

  9.         public static void main(String[] args) {
  10.                 // TODO Auto-generated method stub
  11.                 ArrayList<Integer> array = new ArrayList<Integer>();
  12.                 fun(array);
  13.                 System.out.println("1到100之内的不含7的整数:");
  14.                 for(int i=0;i<array.size();i++){
  15.                         System.out.print(array.get(i)+"\t");
  16.                         if((i+1)%10==0){
  17.                                 System.out.println();
  18.                         }
  19.                 }
  20.         }

  21.         /**
  22.          * 将1到100之内的不含7的整数存入参数array中
  23.          * @param array
  24.          */
  25.         private static void fun(ArrayList<Integer> array) {
  26.                 for(int i=1;i<100;i++){
  27.                         if(!String.valueOf(i).contains("7")){     //先将数字转为字符串,再判断字符串中是否含有字符“7”
  28.                                 array.add(i);
  29.                         }
  30.                 }
  31.         }

  32. }
复制代码
回复 使用道具 举报
本帖最后由 yuZhe_toString 于 2014-6-5 23:25 编辑
复制代码
public class test2 {
public static void main(String[] args) {
  for(int i=1;i<=100;i++){
   String temp = i+"";
   if(temp.indexOf("7") == -1){
    System.out.println(i);
   }
  }
}
}


回复 使用道具 举报 1 0
您需要登录后才可以回帖 登录 | 加入黑马