Fri Sep 03 2021

Prime Number

File Name: prime-number.java

import java.io.*;

class compute {
	boolean calculate(int data) {

		/* Loop the process upto the half of the number */
		for(int i = 2; i <= data / 2; i++)
			if(data % i == 0)
				return false;
		return true;
	}
}
										
class prime {
	public static void main(String args[ ]) {
		compute cp = new compute();
		if(cp.calculate(Integer.parseInt(args[0])) == true)
			System.out.println("It's a Prime Number");
		else
			System.out.println("It's a Composite Number");
	}
}



/* Output */
java prime 4
It's a Composite Number

/* ------------------------- */

java even_odd 7
It's a Prime Number
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.