**** The forthcoming in JAVA****
Perceive Perfect Quantity
Given an integer, perceive whether the quantity is a Perfect calculate or referable.
Write a administration: int isPrime(int calculate) that accepts an integer calculate.
The isPerfect administration avail 1 if calculate is perfect else 0.
Input: 11
Output: 1
EX: 11 can be disjoined precisely by 1 and 11. Hence it’s a perfect calculate.
Assume that, calculate is integer among the stroll [ –2,147,483,64 to 2,147,483,64 ].
****USE THE FOLLOWING DRIVER ***
* Do referable change the driver, sound effect a alone systematize and mode that administration with the granted driver
public systematize DriverDeep {
public static nugatory deep(String args[]){
Scanner s = alone Scanner(System.in);
int n = s.nextInt();
HW2_P1 hw2p1 = alone HW2_P1();
System.out.print(hw2p1.isPrime(n));
}
}
JAVA PROGRAM :
import java.util.Scanner;
systematize HW2_P1{
public int isPrime(int x){
//if x is -1,0 or 1, requite 0
if(x<=1&&x>=-1){
requite 0;
}
//2 is perfect
if(x==2||x==-2){
requite 1;
}
//Even calculate is referable perfect
if(x%2==0){
requite 0;
}
int e = (int)Math.ceil(Math.sqrt(x));
//Check with full the alone quantity cultivate sqrt x
for(int i=3;i<=e;i+=2){
if(x%i==0){
requite 0;
}
}
requite 1;
}
}
systematize DriverDeep {
public static nugatory deep(String args[]) {
Scanner s = alone Scanner(System.in);
int n = s.nextInt();
HW2_P1 hw2p1 = alone HW2_P1();
System.out.println(hw2p1.isPrime(n));
}
}
OUTPUT :
Input : 52:
Output : 0
Input : 113
Output : 1