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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. package com.itheima;

  2. /**
  3. * 第七题: 编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
  4. * @author Machel
  5. */
  6. class Test7{
  7.         public static void main(String[] args){
  8.                 char log = '7';
  9.                 char[] intArr;
  10.                 int num = 0;
  11.                 for(int i=1; i<=100; i++)
  12.                 {
  13.                         intArr = Integer.toString(i*100).toCharArray();
  14.                         for(int j=0; j<3; j++)
  15.                         {
  16.                                 if(intArr[j]==log)
  17.                                         num++;
  18.                         }
  19.                         if(num==0)
  20.                         {
  21.                                 if(i==100)
  22.                                         System.out.print("["+i+"]");
  23.                                 else
  24.                                         System.out.print("["+i+"]"+",");
  25.                         }
  26.                         else
  27.                                 num = 0;
  28.                 }
  29.         }
  30. }
复制代码


42 个回复

正序浏览
回复 使用道具 举报
这个厉害
回复 使用道具 举报
2L厉害,新手看的懂的程序,楼主的那个表示有难度!
回复 使用道具 举报
最好要加一点注释~~
回复 使用道具 举报
温故知新
回复 使用道具 举报
/*打印1到100之内的整数,但数字中包含7的要跳过*/

class MyDemo_TiaoGuo7 {
        public static void main(String[] args)
        {       //以下是方法1
                for(int i = 1; i<=100; i++){
                        int ge = i % 10 ;
                        int shi = i / 10 % 10 ;
                        if (ge ==7 || shi  == 7 )
                        {
                                continue;
                        }
                        System.out.print(i+"  " );
                }
                //以下是方法2
                /*for (int x = 1;x <=100;x++){
                        int y = x/10;
                        if ( x-y*10  == 7|| x/10 == 7){
                                continue;
                        }
                        System.out.print(x+"  " );
                }*/

        }
}
回复 使用道具 举报
真不错啊   学习学习
回复 使用道具 举报
lvzhfeng 发表于 2015-6-26 20:49
最近在学String,脑子都学死了。光往字符串上想了

for(int i = 1;i<=100; i++ )
                {
                        String num = i+"";
                        boolean mi = num.contains("7");
                        if(!mi){
                         System.out.print(i+" ");
                        }
                }
我也是
回复 使用道具 举报
谢谢!我有学到东西了
回复 使用道具 举报
二楼的靠谱,跟我想的一样
回复 使用道具 举报
高手啊,这么简单居然
回复 使用道具 举报
666                     
回复 使用道具 举报
zmttt 中级黑马 2015-12-5 22:07:15
31#
1楼说得对!!
回复 使用道具 举报
学习了不同的方法了
回复 使用道具 举报
二楼的方法确实不错
回复 使用道具 举报
学习了。谢谢分享。。
回复 使用道具 举报
liu100chao 发表于 2015-6-26 18:40
class Test6
{
        public static void main(String[] args)

我敲的代码你你一样,刚打算给楼主回复的!!!!
回复 使用道具 举报
楼主的算法略啰嗦
回复 使用道具 举报
w_wyt 初级黑马 2015-12-4 13:39:14
25#
liu100chao 发表于 2015-6-26 18:40
class Test6
{
        public static void main(String[] args)

这个方法牛逼
回复 使用道具 举报
123下一页
您需要登录后才可以回帖 登录 | 加入黑马