Computer Science, asked by ammuKochu8769, 1 year ago

write a program to create a function which accepts an integer as parameter and return true if it is prime number otherwise return false

Answers

Answered by Navakris
3

import java.util.Scanner;

public class Prime {

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int number = input.nextInt();

 System.out.println(isPrime(number));

}

public static boolean isPrime(int n){

 int i,count = 0;

 for(i = 2; i <= n/2; i++){

  if(n % i == 0)

   count++;

 }

 return count == 0 ? true : false;

}

}

Similar questions