Is it Prime?

Dev Skill archived problems can be discussed here.

Is it Prime?

by arabin » Sat Sep 17, 2016 2:39 pm

hello everyone i am new here and trying to solve the problems. i have submitted my answer for is it prime given below several times but it showed wrong answer anyone please help me to improve my answer.

Code: Select all
class MyClass {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws java.lang.Exception {
        // TODO code application logic here
       
        Scanner kbScanner = new Scanner(System.in);
        int test = kbScanner.nextInt();
        String []answer = new String[test];
        if (test>0&&test<=5000) {
            for (int i = 0; i <test ; i++) {
                int number = kbScanner.nextInt();
                if (number>=0&&number<=10000) {
                    answer[i] = primeDecision(number);
                }
            }
        }
        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";
    }
   
}


thanks in advance
 
Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

Re: Is it Prime?

by arabin » Mon Sep 19, 2016 10:11 pm

anyone please help to improve my coding knowledge. where is the problem in my code
 
Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

Re: Is it Prime?

by devskill » Wed Sep 21, 2016 5:37 am

Please always format your code using the code block, like I have edited now.

Try following I/O

Input:
Code: Select all
2
0
1


Output:
Code: Select all
No
No
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron