KnowledgeBoat Logo

Java Series Programs

Write the program in Java to display the first ten terms of the following series:

1, -3, 5, -7, 9,

Java

Java Iterative Stmts

ICSE

41 Likes

Answer

public class KboatSeriesB
{
    public void displaySeries() {
        
        int term = 1;
        System.out.print(term);
        
        for (int i = 2; i <= 10; i++) {
            
            term += 2;
            
            if (i % 2 == 0)
                System.out.print(", " + (-term));
            else
                System.out.print(", " + term);
        }
    }
}

Output

BlueJ output of Write the program in Java to display the first ten terms of the following series: 1, -3, 5, -7, 9,

Answered By

18 Likes