- Home
- Java Series Programs
Write the program in Java to display the first ten terms of the
Java Series Programs
Write the program in Java to display the first ten terms of the following series:
1, -3, 5, -7, 9,
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);
}
}
}