编写一个程序打印1到100之间的整数,但数字包含7的或者是7的倍数要跳过,
public class Tes_4不包含指定数字 {
public static void main(String[] args) {
String s="";
for (int i = 0; i <100; i++) {
if(i%7!=0 &&!((s+i).contains("7"))){
System.out.println(i);
}
}
}
}
//题目要求:编写一个程序打印1到100之间的整数,但数字包含7的或者是7的倍数要跳过
public class Test {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (hasSeven(i) || divisibleBySeven(i))
continue;
else
System.out.print(i + " ");
}
}
public static boolean hasSeven(int number) {
String s = number + "";
for (int i = 0; i < s.length(); i++) {
if (Character.isDigit(s.charAt(i)) && s.charAt(i) == '7')
return true;
}
return false;
}
public static boolean divisibleBySeven(int number) {
if (number % 7 == 0)
return true;
else
return false;
}
}