write a java program to print a series:
2,4,8,14,22,32....................still more 10 terms
Answers
Answered by
10
Explanation:
please refer to above text
Attachments:
Answered by
3
Below is the program in java for the above question:
Explanation:
public class Series_print // declare a class series_print.
{ public static void main(String[] args)// declaration of main function.
{
int series=2,i=0,j=2; // variable declaration of integer type.
while(i<(16-1)) // while loop to print the series.
{
System.out.print(series+","); // print statement to print the series with comma.
series=series+2*i;// series addition.
i++;// increment for loop.
}
System.out.print(series+".");// print the last element of the series.
}
}
Output:
- The output of the above program is--- 2,4,8,14,22,32,44,58,74,92,112,134,158,184,212,242.
Detailed Explanation:
- The above program prints the series up to 16 terms which is the demand by the above question.
- The above series add the multiple of 2 in every previous value.
- The above program excuses the while loop up to 15 times and prints the value of the series variable after adding a multiple of 2 in previous value separated by the comma.
- The last value of the series print after the while loop.
Learn More:
- Java program: https://brainly.in/question/7382524
- Java program: https://brainly.in/question/3331693
Similar questions