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.
publicclassSolution{publicstaticvoidisPrime(intn){if(n==0||n==1){System.out.println("Not prime");}elseif(n==2){System.out.println("Prime");}else{booleanresult=true;for(inti=2;i<=n/2;i++){if(n%i==0){result=false;break;}}if(result==true){System.out.println("Prime");}else{System.out.println("Not prime");}}}publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intT=sc.nextInt();while(T-->0){intn=sc.nextInt();isPrime(n);}sc.close();}}
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 | Easy Solution