KnowledgeBoat Logo

Computer Applications

Write a program in Java using for loop to print all the odd and even number upto 30 terms.

Java

Java Iterative Stmts

56 Likes

Answer

public class KboatEvenOdd
{
    public static void main(String args[]) {
        System.out.println("Odd numbers: ");
        for (int i = 1; i <= 60; i += 2) {
            System.out.print(i + " ");
        }
        
        System.out.println();
        System.out.println("Even numbers: ");
        for (int i = 2; i <= 60; i += 2) {
            System.out.print(i + " ");
        }
    }
}

Output

BlueJ output of Write a program in Java using for loop to print all the odd and even number upto 30 terms.

Answered By

24 Likes


Related Questions