Java program to find a number is prime or not - C C++ Java Programs - Examples

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, October 10, 2011

Java program to find a number is prime or not


import java.lang.*;
import java.io.*;
class prime
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
for(int r=0;r<n;r++)
{
int t=0;
for(int i=1;i<r;i++)
{
if (r%i==0)
{
t++;
}
}
if(t<2)
{
System.out.print(r);
System.out.print("        "); 
}
}
}
}

No comments:

Post a Comment