Write a program to print numbers 1 to 100

06/11/2013 16:43
public class prime
{
 static boolean prime1(int n)  /* defining a function to check whether the number is prime or not  */
 {
 int sum=0;          /*define a variable to check the number of factors for n*/    
 for(int j=1;j<=n;j++)
 {
 if(n%j==0)
 {
 sum++;
}
}
if(sum==2)
return(true);
else
return(false);
}
public static void main(String args[])
{
for(int i=2;i<=100;i++)
{
if(prime1(i))/* By doing this value of i will be stored in n variable defined in above function*/
{
System.out.println(i);
}
}
}
}