Prime Number Program in Java | Using For Loop

prime number program in java : we are going to start prime number program in java using for loop with example. So There is provided also composite numbers and prime numbers from 1 to 100. After that in this section provide all example Prime number program

Simple Prime Number Program in Java

import java.util.*;
 
class PrimeNumber
{
   public static void main(String args[])
   {
      int n, status = 1, num = 3, count, j;
 
      Scanner in = new Scanner(System.in);
      System.out.println("Enter prime numbers you want");
      n = in.nextInt();
     
      if (n >= 1)
      {
         System.out.println("First "+n+" prime numbers are:");
         System.out.println(2);
      }
     
      for (count = 2; count <=n;)
      {
         for (j = 2; j <= Math.sqrt(num); j++)
         {
            if (num%j == 0)
            {
               status = 0;
               break;
            }
         }
         if (status != 0)
         {
            System.out.println(num);
            count++;
         }
         status = 1;
         num++;
      }        
   }
}

what are prime numbers

prime number program in java

And In this article we are going to finding Prime numbers right all the prime number. So till particular given number there is no need to take all the number. After that you just find the square root of the given number. And if that square root is decimal take the next number. As a result, check the desirably of all available number from 1 till that square root of the number. Therefor using the same principle. We are going to find the prime number between 1 and 100 and method. After that We are going to use is celled Eratosthenes Sieve so let me first

12345678910
11121314151617181920
21222324252627282930
31323334353637383940
41424344454647484950
51525354555657585960
61626364656667686970
71727374757677787980
81828384858687888990
919293949596979899100

prime numbers from 1 to 100

12345678910
11121314151617181920
21222324252627282930
31323334353637383940
41424344454647484950
51525354555657585960
61626364656667686970
71727374757677787980
81828384858687888990
919293949596979899100

How to Find Prime Numbers

In this paragraph This method will be start with from the first row and will go from left to right. And check the desirably of all the number still only 10 why because square root of 100 is 10. So 10*10 give us 100 since 10*10=100 which is the biggest number on this grade. But if you can check desirably of all the numbers till 10 and strike of all the number. Therefor Which are desirable by the numbers till 10 and then will have set of numbers. And create prime number program in java

Prime Number Composite Numbers

As a result Which are still meaning all of then will be prime numbers why because 10 get 10*10= 100 largest numbers in the grade. So there is no need check the desirability but 11 12 13 and so on why because 10*11=110. Which is number bigger than 100 and 10*13 is bigger then 100 so in this particular case. And Actually useless the check desirably of all the numbers by another number. Which is bigger then 10. So Will be start pro cigar and then you will understand. Why i saying this and now lets start the pro cigar. First will start the first row and each row will be go from left to right.

The first will take first row then will take second row and since 10 is first row. We are actually not suppose to go to the second row but to the cross check a logic. you will take the element of the second row also will take number 1 by 1 and then we will cross all the multiple. We will start from 1 and 1 is actually special number it is neither classified as prime number nor as a composite number.

Simple Example to Find Prime Number

Prime Number program in java : we are going to about 1 after this will go check from left to right and check for the still. There uncross how to number after this 2. Therefor 2 is prime number and then what have to do i have strike to all the number. Thus switch are multiple number of 2 so all the number.

Therefor Which are numbers of 2 will be the even numbers on you can peacefully strike of alternate numbers. And every second number of this number Therefor 2 is a prime number first number after 2. 3 and second number after to 4 so 4 is multiple of 2 similar 6 is multiple number of 2. And 8 is a multiple number of 2 all the even number are multiple of 2. 12 is a multiple number of 2 ,14,16,18 and 20 is multiple of 2.

After that we can all this alternate column then have even number. So 3 is prime number All have to red color shade prime number. Thus All highlight number is prime numbers

HTML Syntax : We have to described simple html tags with all information aslo example create your simple page weblearn go to check ..

Latest International news in hindi go to check world technical News on this website

3 Comments

Add a Comment
  1. Great, I really like it! Youre awesome

Leave a Reply

Your email address will not be published. Required fields are marked *

Web Learn Smart © 2019 Frontier Theme