题目:依序遍历0到100闭区间内所有的正整数,如果该数字能被3整除,则输出该数字及‘*’标记;如果该数字能被5整除,则输出该数字及‘#’标记;如果该数字既能被3整除又能被5整除,则输出该数字及‘*#’标记。
/*
* 依序遍历0到100闭区间内所有的正整数,如果该数字能被3整除,则输出该数字及‘*’标记;
* 如果该数字能被5整除,则输出该数字及‘#’标记;
* 如果该数字既能被3整除又能被5整除,则输出该数字及‘*#’标记。
*
* */
public class Test {
public static void main(String[] args) {
int testNun;
for (int i = 0; i < 101; i++) {
System.out.println();
//测试数据赋值,这样不用数组可以解决空间的消耗
testNun = i;
System.out.print(testNun);
if (testNun % 3 == 0)
System.out.print("*");
if (testNun % 5 == 0)
System.out.print("#");
else
continue;
}
}
}
测试结果见链接: 点击打开链接