黑马程序员技术交流社区
标题:
发表一个程序看是否有错
[打印本页]
作者:
天火传说
时间:
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到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
*
* @author sman@mnxnm.com
*
*/
public class 打印不包含特定数字的整数 {
public static void main(String[] args) {
int numMax = 100, numOut = 7;
String strOut = String.valueOf(numOut);
for (int i = 1; i <= numMax; i++) {
String str = Integer.toString(i);
if (!str.contains(strOut)) {
System.out.println(i + " ");
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2