wap in java to display sum of series 1/2,1/3,1/5/1/7,1/11........…...1/29
Answers
Java program to display sum of series : 1/2 + 1/3 + 1/5 + 1/7........1/29
Step-by-step explanation:
Java Program
public class Main {
static boolean check_Prime(int number)
{
if(number== 1) {
return false;
}
for (int i = 2; i*i <= number; i++) {
if (number% i == 0) {
return false;
}
}
return true;
}
static double psum(int l, int r)
{
double sum = 0;
for (int i = r; i >= l; i--) {
boolean is_prime = check_Prime(i);
if (is_prime) {
sum = sum + 1.0/(double)i;
}
}
return sum;
}
public static void main(String[] args)
{
int start = 2, end = 29;
double sumOfseries =psum(start, end);
System.out.println("sum of series : "+sumOfseries);
}
}
Output
sum of series : 1.533438771872032
Answer:
Step-by-step explanation: