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
54 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);
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
23 Likes