https://github.com/mohammedabdulbari/Java-SE/blob/b590bad9ee5b854755e4defa11b42ce759f2db85/SCMethod1.java#L29 If we enter 4 then it will not work , So it should be : `for(int i=2;i<=n/2;i++) ` One more condition at the top if the num ==1 then its not a prime.