Computer Science, asked by somaneogi9, 1 year ago

Write a program in Java to display the first 10 terms of the following series
i) 24,99,224,399,.....
ii) 2,5,10,17,......

Answers

Answered by Anonymous
9

CODE 1 :


class series_1

{

public static void main(String args[])

{

String c1="4";

String c2="99";

for(int i=1;i<=10;i++)

{

if(i%2!=0)

{

System.out.print("2"+c1+" , ");

c1="2"+c1;

}

else

{

System.out.print(c2+" , ");

c2="3"+c2;

}

}//for loop

}//main

}//class


CODE 2:


class series_2

{

public void main(String args[])

{

for(int i=1;i<=10;i++)

{

System.out.print((i*i+1)+" , ");

}

}

}


LOGIC :


First series : for odd positions , 2 is added every time before the number.

For even positions , 3 is added before the number .


__________________________________________


Second series :

1² + 1 = 2

2² + 1 = 4 + 1 = 5

3² + 1 = 9 + 1 = 10

4² + 1 = 16 + 1 = 17

.....


Hope it helps !

_________________________________________________________

Answered by Knowledgeableat2020
1

Answer:

i)public class code1

{

public static void main (String args[])

   {

       for(int a=5;a<=50;a+=5)

       {

           int i = (a*a)-1;

           System.out.print( i +",");

       }

   }

}

ii)public class Code2

{

   public static void main (String args[])

   {

        for(int a=1;a<=10;a++)

       {

            int b = (a*a)+1;

           System.out.print( b +",");

         }

   }

}

Hope this will help you

Similar questions