Java ProgramsControl FlowCheck Number Divisible by 5 and 11

Check Number Divisible by 5 and 11 in Java

beginner·  Control Flow  ·  Conditional Statements

Problem

A number is divisible by both 5 and 11 exactly when it's a multiple of their product, 55 — but checking each modulo condition directly works just as well without needing to know that.

Given a number, determine whether it is divisible by both 5 and 11.

Input
55
Output
55 is divisible by 5 and 11: true

Java Program

Java
public class DivisibleBy5And11 { public static void main(String[] args) { int n = 55; boolean isDivisible = (n % 5 == 0) && (n % 11 == 0); System.out.println(n + " is divisible by 5 and 11: " + isDivisible); } }

Output

55 is divisible by 5 and 11: true

Core Logic

Checking each divisibility condition with the modulo operator, and requiring both to hold, confirms the number is a multiple of both 5 and 11.

How It Works
  1. 1n % 5 == 0 checks divisibility by 5.
  2. 2n % 11 == 0 checks divisibility by 11, combined with &&.
  3. 3Both conditions have to be true at once for the overall result to be true.
For n = 55, both 55 % 5 and 55 % 11 evaluate to 0, so the combined condition is true.
💡

Key Point: Since 5 and 11 share no common factor, a number divisible by both is always a multiple of 55 — but the two separate modulo checks reach the same answer without needing that fact.

Key Concepts

modulo operatorlogical AND

Related Programs