Java program to print the even numbers
KW.java
class KW
{
    public static void main(String args[])
    {
        for(int i=0;i<=10;i++)
        {
            if(i%2!=1)
                System.out.println(i);
        }

        /*
        for(int i=0;i<=10;i++)
            if(i%2==0)
                System.out.println(i);
        */
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 0 2 4 6 8 10 kodingwindow@kw:~$
Java program to print the odd numbers
KW.java
class KW
{
    public static void main(String args[])
    {
        for(int i=0;i<=10;i++)
        {
            if(i%2!=0)
                System.out.println(i);
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 1 3 5 7 9 kodingwindow@kw:~$
Advertisement