<\/span><\/h2>\n\n\n\nYou are given a class Solution and its main method in the editor. Your task is to create a class Prime. The class Prime should contain a single method checkPrime.<\/p>\n\n\n\n
The locked code in the editor will call the checkPrime method with one or more integer arguments. You should write the checkPrime method in such a way that the code prints only the prime numbers.<\/p>\n\n\n\n
Please read the code given in the editor carefully. Also please do not use method overloading!<\/p>\n\n\n\n
Note:<\/strong> You may get a compile time error in this problem due to the statement below:<\/p>\n\n\n\n BufferedReader br=new BufferedReader(new InputStreamReader(in));<\/code><\/pre>\n\n\n\nThis was added intentionally, and you have to figure out a way to get rid of the error.<\/p>\n\n\n\n
<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThere are only five lines of input, each containing one integer.<\/p>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nThere will be only four lines of output. Each line contains only prime numbers depending upon the parameters passed to checkPrime in the main method of the class Solution. In case there is no prime number, then a blank line should be printed.<\/p>\n\n\n\n
<\/span>Sample Input<\/strong><\/span><\/h4>\n\n\n\n 2\n 1\n 3\n 4\n 5<\/code><\/pre>\n\n\n\n<\/span>Sample Output<\/strong><\/span><\/h4>\n\n\n\n 2 \n 2 \n 2 3 \n 2 3 5 <\/code><\/pre>\n\n\n\n<\/span>Solution – Prime Checker<\/strong> in Java<\/strong><\/span><\/h2>\n\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.lang.reflect.*;\nimport static java.lang.System.in;\n\nclass Prime {\n void checkPrime(int... numbers) {\n for (int num : numbers) {\n if (isPrime(num)) {\n System.out.print(num + \" \");\n }\n }\n System.out.println();\n }\n \n boolean isPrime(int n) {\n if (n < 2) {\n return false;\n } else if (n == 2) {\n return true;\n } else if (n % 2 == 0) {\n return false;\n }\n int sqrt = (int) Math.sqrt(n);\n for (int i = 3; i <= sqrt; i += 2) {\n if (n % i == 0) {\n return false;\n }\n }\n return true;\n } \n}\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\ttry{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(in));\n\t\tint n1=Integer.parseInt(br.readLine());\n\t\tint n2=Integer.parseInt(br.readLine());\n\t\tint n3=Integer.parseInt(br.readLine());\n\t\tint n4=Integer.parseInt(br.readLine());\n\t\tint n5=Integer.parseInt(br.readLine());\n\t\tPrime ob=new Prime();\n\t\tob.checkPrime(n1);\n\t\tob.checkPrime(n1,n2);\n\t\tob.checkPrime(n1,n2,n3);\n\t\tob.checkPrime(n1,n2,n3,n4,n5);\t\n\t\tMethod[] methods=Prime.class.getDeclaredMethods();\n\t\tSet<String> set=new HashSet<>();\n\t\tboolean overload=false;\n\t\tfor(int i=0;i<methods.length;i++)\n\t\t{\n\t\t\tif(set.contains(methods[i].getName()))\n\t\t\t{\n\t\t\t\toverload=true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset.add(methods[i].getName());\n\t\t\t\n\t\t}\n\t\tif(overload)\n\t\t{\n\t\t\tthrow new Exception(\"Overloading not allowed\");\n\t\t}\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\tSystem.out.println(e);\n\t\t}\n\t}\n\t\n}<\/pre>\n\n\n\n