1. 程式人生 > >Java判斷某數能否被3,5,7同時整除

Java判斷某數能否被3,5,7同時整除

思路:判斷該數分別除以3,5,7的餘數是否為零,利用if...else語句進行輸出

import java.util.Scanner;

public class Four62 {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);	//從鍵盤輸入
		System.out.print("請輸入num值:");
		int num = scan.nextInt();
		int i = num % 3;
		int j = num % 5;
		int k = num % 7;
		if(i==0&&j==0&&k==0) {
			System.out.println(num+"能被3,5,7同時整除");
		}
		else {
			System.out.println(num+"不能被3,5,7同時整除");
		}
		scan.close();

	}

}