Write a java program to input a number n and find the sum of prime numbers between 1 and n.
Answers
Answered by
2
import java.io.*;
import java.util.*;
class sum
{
public static void main (String args[ ])
{
int n,i=1, s=0;
Scanner sc=new Scanner (System.in);
System.out.println("Enter the number n:");
n=sc.nextInt();
while(i<=n)
{
s=s+i;
I=i+2;
}
System.out.println("The required sum is:"+s);
}
}
Similar questions