find the sequence of 1,9,25,49in Java programming
Answers
Answered by
1
Explanation:
this is very easy sequence, it is the square of odd numbers
1² ,3²,5²,7²
it's program -
class app
{
public static void main ()
{
for(int i = 1; i <= 7;i = i + 2)
{
if (i == 7)
System.out.print(i*i);
else
System.out.print((i*i)+" ,");
}
}
}
output
1 ,9 ,25 ,49
Answered by
31
Question:-
WAP to display the following sequence.
1 9 25 49.....
Code:-
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the total number of terms for thr series: ");
int n=sc.nextInt();
int a=1;
for(int i=1;i<=n;i++,a+=2)
System.out.print(a*a+" ");
}
}
Similar questions