PRINT THE NUMBER 1 TO 50 DIVIDED BY 2 4 AND 6.

The logic in this programe, the modulus operation determines the remainder of the division operation of the two numbers,by definition, is any number divisible by two,four,six.

Therefore, if a number which returns a zero for a remainder when modulus 2,4,6.

More simply, a number "i" is even if "i % 2","i % 4","i % 6" equals zero from 0 to 50.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    public class DividNum
    {
        public static void main(String[] args)
        {
            int i,c=0;
            System.out.println("enter numbers 1 to 50 which are divided by only 2 4 6");
            for(i=0;i<=50;i++)
            {
                if(i%2==0&&i%4==0&&i%6==0)
                {
                    System.out.println(""+i);
                    c++;
                }  
            }
            System.out.println("Total Numbers:="+c);       
        }
    }

    Output :Print the Numbers
    oddeven