# Homework Solution: **** The following in JAVA****…

**** The following in JAVA**** Find Prime Numbers Given an integer, find whether the numbers is a Prime number or not. Write a function: int isPrime(int number) that accepts an integer number. The isPrime function returns 1 if number is prime else 0. Input: 11 Output: 1 EX: 11 can be divided exactly by 1 and 11. Hence it's a prime number. Assume that, number is integer within the range [ –2,147,483,64 to 2,147,483,64 ]. ****USE THE FOLLOWING DRIVER *** * Do not modify the driver, just make a new class and method that function with the provided driver public class DriverMain { public static void main(String args[]){ Scanner s = new Scanner(System.in); int n = s.nextInt(); HW2_P1 hw2p1 = new HW2_P1(); System.out.print(hw2p1.isPrime(n)); } }

JAVA PROGRAM : import java.util.Scanner;

**** 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));

}

}

## Expert Vindication

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