V. Unsolved Java Programs:
1. Write the programs in Java to display the first ten terms of the following series
(a) 1, 4, 9, 16,
Answers
Answered by
4
Printing given series: 1, 4, 9 16......
Output:
1,4,9,16,25,36,49,64,81,100,121,144,169,196,
Explanation:
Program:
import java.util.*; //import package
public class Main //defining class
{
public static void main(String[] args)//defining main
{
int i,odd=1,sum=0;//defining integer variable
for(i=1;i<15;i++) //loop for incremeting value
{
sum=sum+odd;//calculate value
odd=odd+2; //adding value
System.out.print(sum+","); //print series
}
}
}
Description of above code:
- In the above code, firstly import the package, then defining the main class, inside this class, the main method is declared, in this three integer variable "i, odd, and sum " is defined.
- In this variable, i is used in the loop and "sum and odd" is used inside the loop, sum variable uses the odd and odd is increment its value by 2.
- In the last step, the print method has used, that prints the given series.
Learn more:
- Print series: https://brainly.in/question/9362688
- Series in java: https://brainly.in/question/7426230
Similar questions