你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

输入一个数没判断能否被3,5,7其中的任何一位或者两位或者能被三位同时整除

2021/12/26 11:40:29
package demo10_28;

import java.util.Scanner;

public class test5 {

	public static void main(String[] args) {
		int i;
		for (i = 0; i < 1000; i++) {
			System.out.println("请输入一个整数");
			Scanner sc = new Scanner(System.in);
			int y = sc.nextInt();
			if (y % 3 == 0) {
				if ((y % 5 == 0) && (y % 7 == 0)) {
					System.out.println("能被3,5,7整除");
				} else if (y % 5 == 0) {
					System.out.println("能被3,5整除");
				} else if (y % 7 == 0) {
					System.out.println("能被3,7整除");
				} else {
					System.out.println("能被3整除");
				}
			} else if (y % 5 == 0) {
				if (y % 7 == 0) {
					System.out.println("能被5,7整除");
				} else {
					System.out.println("能被5整除");
				}
			} else if (y % 7 == 0) {
				System.out.println("能被7整除");
			}
			else {System.out.println("不能被3,5,7中任意一个数整除");}
			System.out.println("\n");
		}
	
	}
}