Write a program in java to print the following series up to 10 terms:
0,3,8,15,24,35,…………10 terms
Answers
Answer:
public class Series // Class definition
public static void main(String[] args) // Main function declaration
int i=0,series=0,s=0; // variable declaration while(i<10) // while loop to repeat the process 10
times.
{
System.out.print(series+", "); // Print the series series=series+3+s; // Make the series
i=i+1; // increment operator
s=s+2; // increase for series
}
}
}
Output:
The user get "O, 3, 8, 15, 24, 35, 48, 63, 80, 99," as output because it is a series which is demand by the question.
Explanation:
The above series is like this -- 0, 0+3, (0+3)+3+2, (0+3+3+2)+3+2 and so on.
• Then the above program declares a while loop which executes 10 times.
• Then it takes one variable which prints the value after adding the previous value and 3 and the s variable (which starts from 0 and adds 2 value in previous value in every iteration of while loop).