以下是一个Java程序,可以找出0~100之间所有能被6整除的数,并判断89到100之间是否存在可以整除六的数:
Copy code
public class FindNumbers {
public static void main(String[] args) {
// 找出0~100之间所有能被6整除的数
System.out.println("0~100之间所有能被6整除的数为:");
for (int i = 0; i <= 100; i++) {
if (i % 6 == 0) {
System.out.print(i + " ");
}
}
System.out.println();
// 找出89~100之间是否存在可以整除六的数
System.out.println("89~100之间可以整除六的数为:");
boolean hasDivisible = false;
for (int i = 89; i <= 100; i++) {
if (i % 6 == 0) {
hasDivisible = true;
System.out.print(i + " ");
}
}
if (!hasDivisible) {
System.out.println("没有可以整除六的数");
}
}
}
在程序中,使用 for 循环遍历0~100之间的所有整数,并使用 if 语句判断每个整数是否能被6整除。如果能,就将这个整数输出到屏幕上。
接着,程序再次使用 for 循环遍历89~100之间的所有整数,并使用 if 语句判断每个整数是否能被6整除。如果能,就将这个整数输出到屏幕上,并记录下是否存在这样的整数
温馨提示:答案为网友推荐,仅供参考