In this tutorial we are going to create a small little program that show us if a number is primary or not!
Here is the code:
import java.io.*; class primary { public static void main(String[]args) throws IOException { long x; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("x= "); x=Long.parseLong(br.readLine()); if(estePrim(x)) System.out.println(x+" is a primary number"); else System.out.println(x+" is NOT a primary number"); } static boolean estePrim(long nr) { if((nr==0) || (nr==1)) return false; if((nr==2) || (nr==3)) return true; if(nr%2==0) return false; long d=3; while ((nr%d!=0) && (d*d<=nr)) d=d+2; if(nr%d==0) return false; else return true; } }
Here is the code screenshot:
Now, here is the compiled version screenshot: