187k views
0 votes
in java programming code Assume you have a variable called m that is declared to be an int. Write the code to print out “m is a multiple of 3 and 5” if m is a multiple of both 3 and 5. The code should also print out “m is not a multiple of 3 and 5” if m is not a multiple of both 3 or 5.

User CeamKrier
by
8.4k points

1 Answer

4 votes

int m = 15; // Example value for m

if (m % 3 == 0 && m % 5 == 0) {

System.out.println("m is a multiple of 3 and 5");

} else {

System.out.println("m is not a multiple of 3 and 5");

}

In this code, we're using the modulo operator (%) to check whether m is a multiple of 3 and 5. If m is divisible by both 3 and 5 (i.e., the remainder when m is divided by 3 and 5 is 0), then we print the message "m is a multiple of 3 and 5". Otherwise, we print the message "m is not a multiple of 3 and 5". Note that the value of m is arbitrary and can be changed to any other value as needed.

User Rck
by
8.1k points

No related questions found