Computer Applications
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);
}
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write the program in Java to display the first ten terms of the following series:
1, 11, 111, 1111,
Write the program in Java to display the first ten terms of the following series:
0, 1, 2, 3, 6,
Write the program in Java to display the first ten terms of the following series:
1, 12, 123, 1234,
Write the program in Java to display the first ten terms of the following series:
0, 3, 8, 15,