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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yuhongzhen 中级黑马   /  2015-11-27 21:50  /  1234 人查看  /  12 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

题目:编写一个方法,100以内的数逢7的去掉,输出其余的数。
      我只想到一种方法,将整数转化为字符串,使用contains方法进行判断,请问还有其他方法吗?有知道的请指教。
public static void main(String[] args) {
                // TODO Auto-generated method stub
                for(int i=1;i<100;i++){
                        String s=Integer.toString(i);
                        if(!s.contains("7")){
                                System.out.println(s);
                        }
                }
        }

12 个回复

倒序浏览
从个位十位百位分别进行判断  是否等于7
回复 使用道具 举报
两个判断条件,%10==7和/10==7 一个是找17 27这种,另一个是找70-79
回复 使用道具 举报
hyl 中级黑马 2015-11-28 15:48:14
板凳
看不懂啊,是不是学的太不好了啊
回复 使用道具 举报
feng0606 发表于 2015-11-28 15:10
两个判断条件,%10==7和/10==7 一个是找17 27这种,另一个是找70-79

嗯  这样子可以 还有其他的途径没有
回复 使用道具 举报
循环,用continue关键字就可以了
回复 使用道具 举报
startsWith ,endsWith
回复 使用道具 举报
feng0606 发表于 2015-11-28 15:10
两个判断条件,%10==7和/10==7 一个是找17 27这种,另一个是找70-79

嗯,这个好,,
回复 使用道具 举报
这个必须顶
回复 使用道具 举报
我也遇到了这个问题
回复 使用道具 举报
//编写一个方法,100以内的数逢7的去掉,输出其余的数 public class Demo {         public static void main(String[] args) {                 getNum1();         }         //定义一个函数来实现功能         //可以分别判断十位(x/10)与各位(x%10)上的数是否为7         public static void getNum1(){                 for (int i = 1; i <100; i++) {                         //判断十位和各位上的数是否为7                         if (i/10 == 7 || i%10==7) {                                 System.out.println(i);                         }                 }         }  }
回复 使用道具 举报
//编写一个方法,100以内的数逢7的去掉,输出其余的数
public class Demo {
        public static void main(String[] args) {
                getNum1();
        }
        //定义一个函数来实现功能
        //可以分别判断十位(x/10)与各位(x%10)上的数是否为7
        public static void getNum1(){
                for (int i = 1; i <100; i++) {
                        //判断十位和各位上的数是否为7
                        if (i/10 == 7 || i%10==7) {
                                System.out.println(i);
                        }
                }
        }
}
回复 使用道具 举报
//逢7的去掉,输出其他数字
public class Text {
        public static void main(String[] args) {

                for (int x = 1; x <= 100; x++) {
                        if (x / 10 == 7 || x % 10 == 7) {
                               
                        }else{
                                System.out.println(x);
                        }
                }

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