面试题——整除问题Java实现

来源:互联网 发布:合金装备5幻痛捏脸数据 编辑:程序博客网 时间:2024/06/08 06:22

题目:依序遍历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("#");elsecontinue;}}}

测试结果见链接:点击打开链接


0 0
原创粉丝点击