Computer Science, asked by gooddino, 17 days ago

1. Write a class using a function primeCheck(int num) to check whether a given number is Prime or not. Function should return a value true if number is prime otherwise it return false if not. void display() -Accept an integer and check whether it is a prime number or not using primecheck()​

Answers

Answered by gnanaharish03
1

Answer:

Python :

def primeCheck (num):

for i in range(2, num):

if num % i == 0:

return False

return True

n = 8

print(primeCheck(8))

Java :

public boolean primeCheck(int num){

int i;

for( i = 2; i < num; i++){

if( num % i == 0)

return false

return true

}

}

Explanation:

So 1 is neither a prime nor a composite , keeping that in mind we iterate through 2 to the number which is less than the given number , if any of this number divides our given number then our given number is not a prime hence return false, else return true.

Similar questions