Tuesday, February 18

Finding Prime Number Series Using Static Method in Java.



Hi ALL,

Here I wrote a program for Finding Prime Number Series Using Static Method in java.

/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;
public class PrimeNumber {
    public static void main(String arg[]){
        System.out.println(" Prime Number Serious ");
      
       Scanner s = new Scanner(System.in);
       System.out.print("Enter the first number number : ");
       int start = s.nextInt();
       System.out.print("Enter the second number number : ");
       int end = s.nextInt();
       System.out.println("List of prime numbers between " + start + " and " + end);
       for (int i = start; i <= end; i++) {
           if (isPrime(i)) {
               System.out.println(i);
           }
       }
   }

   public static boolean isPrime(int n) {
       if (n <= 1) {
           return false;
       }
       for (int i = 2; i < Math.sqrt(n); i++) {
           if (n % i == 0) {
               return false;
           }
       }
       return true;
   }
}

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...