Divisible by Both 6 and 8 in Java
We discuss Divisible by Both 6 and 8 in Java in this class.
The reader should have prior knowledge of loops in Java. Click Here.
It is our first program on loops.
Question:
Write a program to display numbers divisible by both 6 and 8.
Note: Numbers from 1 to 100
The below diagram shows the code.
As we discussed in previous classes loop needs three steps.
We initialized the variable i=1.
Condition is i <=100 because we need numbers from 1 to 100.
Each time in the loop, we need to check the condition number divisible by 6 and 8.
Number modulus six is used to check whether it is divisible or not.
If the modulus value is zero, the number is divisible.
If ((i%6==0)&&(i%8==0)) is used to check the number divisible by 6 and 8.
Output: 24, 48, 72, 96