Using own method in Java to test a number is prime or not
Hi! I wrote a program to check a number is prime or not using a boolean method. Here is my code: package prim; import java.util.Scanner; public class Prim { public static boolean isPrime(int num) { if ( num % 2 == 0 && num > 2 && num % 1 == 0) { return false; } return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Kérem a számot, amiről el kell döntenem, hogy prím-e: "); int n = sc.nextInt(); while (n < 2) { System.out.print("Kérem a számot, amiről el kell döntenem, hogy prím-e: "); n = sc.nextInt(); } boolean m = isPrime(n); if (isPrime(n)) { System.out.println("A szám prím."); } else { System.out.println("A szám nem prím."); } } } The problem is, it says to 45 and 93 are prime numbers, but they aren't. Where's the problem in the code? Thanks in advance.