Question #3529

Test if a number is a multiple of 3, 5 or 7.

Expert's answer

import java.util.Scanner;




public class Main {




public static void main(String[] args) {




int n;

Scanner in = new Scanner(System.in);

System.out.print("Enter a number: ");

n = in.nextInt();

if(n % 3 == 0)

System.out.println(n + " is a multiple of 3");

if(n % 5 == 0)

System.out.println(n + " is a multiple of 5");

if(n % 7 == 0)

System.out.println(n + " is a multiple of 7");

if((n % 3 != 0)&&(n % 5 != 0)&&(n % 7 != 0))

System.out.println(n + " is a not multiple of 3, 5 or 7");

}




}
LATEST TUTORIALS
APPROVED BY CLIENTS