Fri Sep 03 2021
Prime Number
Java Programming1111 views
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
Author:Geekboots