public class Main { public static void main(String[] args) { int num =0,counter=0, i =0,sum=0; double average=0; System.out.println("Prime numbers from 1 to 100 are :"); for (i = 1; i <= 100; i++) { counter=0; for(num =i; num>=1; num--) { if(i%num==0) { counter = counter + 1; } } if (counter ==2) { System.out.print(i+" "); sum=sum+i; } } System.out.println("sum is "+sum); average=sum/counter; System.out.println("average is "+average); } }
Prime numbers from 1 to 100 are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
sum is 1060
average is 117.0