Prime Number Verification : Java Program Code Along With First 100 Prime Numbers

Prime Number is one of the fundamental concepts of mathematics .Prime number can be defined as :start programming in java
The number which is divisible only by itself and 1 . That is other than two numbers (itself and 1) no other number can give remainder 0 .

But still when comes to coding prime number coding in Graphical user interface representation , its not that easy .start programming in java

for e.g

23 , divisible by 1 and 23 only , thus its a prime numberstart programming in java
20, divisible by 1,2,4,5,10.20 , thus it is not a prime number

Read Also :  Scheduling Algorithm : First Come First Serve (Fcfs)

Best efficient method to compute the prime number is to square root the number .  That is , if the number is prime then there will be no multiple of the number between 1 and the square root of the number .
Let us understand above statement with an examplestart programming in java

Suppose we want to check whether 7687  is a prime number or not
So applying above method ,
Observing the number , the square root should lie between 80 (square of 80 is 6400) and 90 (square of 90 is 8100) . So we conclude that the square root of 7687 is smaller than 90 .
Now we just need to divide the given number 7687 from 2 to 90 , if any number is a multiple of the number
,than , the number is not prime , else the number is prime .
After you do calculation for the above given number 7687 , you will find that the number is prime.start programming in java

Pseudo code :

1. Find out the square root of  the given number
2. Now consider square root value as the upper limit or the value upto which we need to decide whether the
    given number is prime or not .start programming in java
3. Use hit and trial method , and divide the given number (for eg. 7687)  from 2 to the square root of
    value(90)  .
4. If there is any value which gives 0 remainder or a multiple of given number then the number is not prime
    and exit .    
5. If value reaches equal to the square root value i.e upper limit and there is no value whose remainder is 0
    or multiple or factor of the given value ,then number is  prime and exit .

List of Prime numbers upto 100 :start programming in java


Read Also  :   Quadratic Probing And Linear Probing 

start programming in javaprime number gui java code output image
Demo :
start programming in java
so , when you run the program in the command prompt , then a gui pops up . Enter the number which you need to check , whether its a prime number or not , and then click ok . The text field with label Prime will automatically show the result by rendering true or false in the text field.

start programming in java
import java.awt.*;
import java.awt.event.*;

public class prime implements ActionListener,KeyListener
Frame f;
Label one,two;
TextField three,four;
Button five;
int i,t,j;
String s1="";
public prime()
f=new Frame("Prime Number");
one=new Label("Enter the number");
two=new Label("Prime ");
three=new TextField(5);
four=new TextField(5);
five=new Button("OK");
public void keyPressed(KeyEvent k)
public void keyTyped(KeyEvent k)
s1+= k.getKeyChar();
public void keyReleased(KeyEvent k)
public void actionPerformed(ActionEvent ae)

public static void main(String s[])
new prime();
Prime Number Verification : Java Program Code Along With First 100 Prime Numbers Prime Number Verification : Java Program Code Along With First 100 Prime Numbers Reviewed by Anonymous J on 05:51 Rating: 5

No comments:

Powered by Blogger.