by arabin » Sun Aug 07, 2016 12:43 pm
Is it prime problems solutions show time limit exceeded but my code is perfect i think
- Code: Select all
import java.util.Scanner;
/**
*
* @author arabin
*/
class MyClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner kbScanner = new Scanner(System.in);
int test = kbScanner.nextInt();
String []answer = new String[test];
if (test>0) {
for (int i = 0; i <test ; i++) {
answer[i] = primeDecision(kbScanner.nextInt());
}
}
for (int i = 0; i < answer.length; i++) {
System.out.println(answer[i]);
}
}
private static String primeDecision(int nextInt) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if (nextInt == 2) {
return "Yes";
}
else{
for (int i = 2; i <nextInt ; i++) {
if (nextInt%i == 0 ) {
return "No";
}
}
}
return "Yes";
}
}