447,889 views
6 votes
6 votes
Class Main {

/*
In this program, you will use boolean expressions to check if 5 is a prime number.
Recall that a prime number is an integer number that is only divisible by 1 and itself. For example, 3 is a prime number because it’s only divisible by 1 and 3 and no other numbers, but 4 is not a prime number because it’s divisible by 2 as well as 1 and 4.
*/

public static void main(String[] args) {
int number = 5;
System.out.println("A prime number is only divisible by 1 and itself (except 1 and 2).");
System.out.print("Is " + number + " a prime number? ");
boolean isPrimeNumber = false;
isPrimeNumber = TODO
if (isPrimeNumber)
System.out.println("Yes");
else
System.out.println("No");
}
}

Please answer with programming language Java. The question is what to put in the TODO spot.

User George Bora
by
3.0k points

1 Answer

22 votes
22 votes

class check_prime {

public static void main(String[] args) {

int number = 5;

System.out.println("A prime number is only divisible by 1 and itself (except 1 and 2).");

System.out.print("Is " + number + " a prime number? ");

boolean isPrimeNumber = (number%2==0) ? false : (number%3==0) ? false : (number%4==0) ? false : true;

if (isPrimeNumber)

System.out.println("Yes");

else

System.out.println("No");

}

}

User Else
by
3.0k points