CBSE Class 12 IP (Informatics Practices) Java Project / Practical Assignment - How to Know if a Number is Prime or not - Generating Prime Numbers Between A Given Range

In this article, we're providing you with code for Java Netbeans Desktop programming on how to know in Java if a number is prime or not . This type of assignments are part of CBSE Class 12 IP Java Projects or CBSE Class 12 IP Java Practical Assignments. Following is the Java code for the program:

 

Code for Generate Button:

String a=TF1.getText();
        if(a.equals(""))
        {
            JOptionPane.showMessageDialog(null,"This field can't be left blank.");
        }
        else
        {
            int lower,upper,i,j,k;
            lower=Integer.parseInt(TF1.getText());
            upper=Integer.parseInt(TF2.getText());
            for(i=lower; i<=upper; i++)
            {
                k=0;
                {
                    for(j=2; j<i; j++)
                    {
                        if((i%j)==0)
                        {
                            k=1;
                        }
                    }
                    if(k==0)
                    {
                        String s=TF3.getText();
                        TF3.setText(s + i + ",");
                    }
                }
            }
            
        }
 

 

If you liked this article and think it was a help to you, please like us on Facebook (you can use the Facebook Like widged on the left side bar on this page). Also, you can like this very page by clicking on the like button at the top of the page. Thank you.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>