Grokking Java Basics
0% completed
Check if a Number is Prime
Problem Statement
Write a Java program to check if a given number is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, whereas 4, 6, 8, and 9 are not.
Examples
Example 1:
- Input:
7 - Output:
7 is a prime number. - Justification: The number
7has no divisors other than1and7, making it a prime number.
Example 2:
- Input:
10 - Output:
10 is not a prime number. - Justification: The number `10
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%