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.
`**Java Best Solution to Understand **
import java.io.;
import java.util.;
public class Solution {
public static String prime(int n){
for (int i = 2; i < Math.sqrt(n); i++) {
if (n%i==0) {
return "Not prime";
}
}
return "Prime";
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
int j = sc.nextInt();
a.add(j);
}
for (Integer i : a) {
System.out.println(prime(i));
}
}
}
`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
`**Java Best Solution to Understand ** import java.io.; import java.util.;
public class Solution {
} `