
Calculate and display the sum of all prime number from 1 to 100 covert in java system codes

Hi Friend,
Try the following code:
class PrimeNumbers{
public static void main (String args[]){
String primeNo = "";
int sum=0;
int j=0;
System.out.println("Prime nums are:" );
for (int i = 1; i < 100; i++){ {
for ( j = 2; j < i; j++){
if (i % j == 0) {
break;
}
}
if (i == j) {
primeNo += i + " ";
sum+=i;
}
}
}
System.out.println(primeNo);
System.out.println("Sum of Prime Numbers: "+sum);
}
}
Thanks

Hi friend Try this code....... *import java.io.; class today2 { public static void main(String args[])throws IOException { BufferedReader obg=new BufferedReader(new InputStreamReader(System.in)); String str=obg.readLine(); int num=Integer.parseInt(str); int sum=0; //int test=5; for(int i=2;i<=num;i++) { if(num%i==0) { sum=sum+i; } } System.out.println("Result"+sum); } }**
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.