/*WAP to print prime no. b/w 1 to 100*/
/*Save as: demo_sprime.java*/
import java.lang.*; class sprime { int num,count=0; sprime(int a) { num=a; } void display() { for(int i=1;i<=num;i++) { for(int j=1;j<=i;j++) { if(i%j==0) count++; } if(count<3) { System.out.println(i); count=0; } else count=0; } } } class demo_sprime { public static void main(String arg[]) { sprime p1=new sprime(100); p1.display(); } }
No comments:
Post a Comment