i need a simple program from printing odd and even numbers from 1 to 100?

JAVA program

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    class A

    {

    public static void main(String arg[])

    {

    int s=0;

    System.out.print("Even Numbers are");

    for(int i=1;i<=100;i++)

    {

    if(i%2==0)

    {

    System.out.println(i);

    }

    }

    System.out.println("Odd Numbers are");

    for(int i=1;i<=100;i++)

    {

    if(i%2!=0)

    {

    System.out.println(i);

    }

    }

    }

    }

  • Bill
    Lv 4
    1 decade ago

    Use mod (%)

    like this:

    if(N%2==1) {

    //N is odd, act accordingly

    }

    else {

    //N is even, act accordingly

    }

Still have questions? Get your answers by asking now.