Java program to Find whether number is Prime or Not

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class PrimeNo{
	public static void main(String args[]){
		int num = Integer.parseInt(args[0]);
		int flag=0;
		for(int i=2;i<num;i++){
			if(num%i==0)
			{
				System.out.println(num+" is not a Prime Number");
				flag = 1;
				break;
			}
		}
		if(flag==0)
			System.out.println(num+" is a Prime Number");
	}
}

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

22 Responses to “Java program to Find whether number is Prime or Not”

  1. noopur mukati

    if i enter number “1″ or “0″ this code is giving me that it is prime but it is not y??

    Reply

Leave a Reply