Computer Science, asked by wadia1337, 10 months ago

Wap in java to print series of 0,2,5,10,17,28

Answers

Answered by anuragmukherjee74
0

Answer:

// Java program to find the N-th term of the series:

// 5, 10, 17, 26, 37, 50, 65, 82, ...

import java.util.*;

class solution

{

// calculate Nth term of series

static int nthTerm(int n)

{

//return the final sum

return (int)Math.pow(n, 2) + 2 * n + 2;

}

// Driver Function

public static void main(String arr[])

{

int N = 4;

System.out.println(nthTerm(N));

}

}

HOPE THE ANSWER HELPS YOU.....

PLEASE MARK ME AS BRAINLEAST.....

Answered by anindyaadhikari13
1

Question:-

Write a program in Java to print the series

0 2 5 10 17 28....

Program:-

import java.util.*;

class Series

{

static boolean isPrime(int n)

{

int c=0;

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

{

if(n%i==0)

c++;

}

return (c==2);

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the number of terms for the series: ");

int n=sc.nextInt();

int a=0, c=1;

for(int i=1;c<=n;i++)

{

if(isPrime(i))

{

System.out.print(a+" ");

a+=i;

c++;

}

}

}// end of main

}// end of class

Similar questions