We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Advanced
- Prime Checker
- Discussions
Prime Checker
Prime Checker
Sort by
recency
|
343 Discussions
|
Please Login in order to post a comment
**Why do they add 4th and 5th together instead of individually? **
Shouldn't the result of such a task include 5 lines of solution instead of 4?
ob.checkPrime(n1); ob.checkPrime(n1,n2); ob.checkPrime(n1,n2,n3); ob.checkPrime(n1,n2,n3,n4,n5);
**Why they did it like that? **
For me better will be sth like this: import java.util.*;
public class Solution {
}
class Prime{
}
Here is my solution to this problem:
` public class Solution {
static class Prime { public void checkPrime(int... numbers) { for (int num : numbers) { if (isPrime(num)) { System.out.print(num + " "); } } System.out.println(); }
} } `
this is a very simple way to check PrimeNumber static class Prime {