Assignment:
isPrime Method
A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly 1, 2, 3, and 6.
Write a method named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Demonstrate the method in a complete program.
package isprimemethod; import javax.swing.JOptionPane; /** * * @author uuuuuuu */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { String input; int num; boolean bool; input = JOptionPane.showInputDialog("Enter an integer."); num = Integer.parseInt(input); bool = isPrime(num); System.out.println(bool); } public static boolean isPrime(int num) { boolean bool; { if(num%1==0 && num%num==0) bool = true; else bool = false; } return bool; } }
I tried a few numbers out but the outcome is always "true". No outcome came out to be "false".
What is wrong with the code?