90 views
0 votes
Write a program where you ask the user for an integer number. The program should determine if that number is a multiple or not of 2, 3, and 5. As an example, if the user inputs 12, it should print:

The value 12 is a multiple of 2
The value 12 is a multiple of 3
The value 12 is not a multiple of 5

1 Answer

5 votes

Final answer:

To determine if a number is a multiple of 2, 3, and 5 in Java, the program can use the modulo operator (%) to check if the remainder of dividing the number by the divisor is zero. This approach helps determine if the number is a multiple or not.

Step-by-step explanation:

To solve this problem, we can use the modulo operator (%) in Java to determine if a number is a multiple of another number. We need to check if the user's input is divisible by 2, 3, and 5 using the modulo operator and print the appropriate message based on the result. Here's an example program:

import java.util.Scanner; public class MultipleChecker {public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter an integer number:"); int number = scanner.nextInt(); if (number % 2 == 0 System.out.println("The value " + number + " is a multiple of 2"); } if (number % 3 == 0) {System.out.println("The value "number + " is a multiple of 3"); } if (number % 5 == 0) { System.out.println("The value " + number + " is a multiple of 5"); else { System.out.println("The value " + number + " is not a multiple of 5");}}}

In this program, we use the modulo operator (%) to check if the remainder of dividing 'number' by a specific divisor is equal to zero, which indicates that 'number' is divisible by that divisor.

User Michael Gendin
by
7.8k points