Computer Science, asked by sugrivshahi1949, 1 year ago

write the program in Java to display the first n terms of 1,4,9,16,..............​

Answers

Answered by kumarimranju83
2

Answer:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

import java.io.*;

class SquareSeries

{

   public static void main(String args[]) throws IOException

   {

       int n;

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

       System.out.println(\"Enter no.of elements in series: \");

       n = Integer.parseInt(br.readLine());

 

       if(n>0)

       {

           System.out.println(\"Series:\");

           for(int i=0; i<(n-1); i++)

           {

               System.out.println(\"\\t\"+(int)(Math.pow(i,2)));

           }

       }

 

       else

           System.out.println(\"You Entered the Wrong no.\");

 

   }

}

 

OUTPUT:  

Enter no.of elements in series:

6

Series:

   0

   1

   4

   9

   16

   251

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

import java.io.*;

class SquareSeries

{

   public static void main(String args[]) throws IOException

   {

       int n;

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

       System.out.println(\"Enter no.of elements in series: \");

       n = Integer.parseInt(br.readLine());

 

       if(n>0)

       {

           System.out.println(\"Series:\");

           for(int i=0; i<(n-1); i++)

           {

               System.out.println(\"\\t\"+(int)(Math.pow(i,2)));

           }

       }

 

       else

           System.out.println(\"You Entered the Wrong no.\");

 

   }

}

 

OUTPUT:  

Enter no.of elements in series:

6

Series:

   0

   1

   4

   9

   16

   25

Similar questions