March 17, 2013

Find Prime Number in java

how to determine prime number in java


package prime Algorithm.Testing;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *java practical question
 * @author joseph
 */

/**
 * @author Samsung Galaxy S4
 *
 */
public class PrimeOrNot {

    /**
     * @param args
     */
      static int i,num,flag=0;
   
    public static void main(String[] Lumina) {
        // TODO Auto-generated method stub
   
        System.out.println(" To find prime number in java : enter the integer no:");
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       try {
         num=Integer.parseInt(br.readLine());
    } catch (NumberFormatException phpexp) {
        // TODO Auto-generated catch block
        phpexp.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
       for(i=2;i           if(num%2==0)
           {
               flag=1;break;
           }
       }
       if(flag==1)
           System.out.println("Number is not prime");
       else
           System.out.println("Number is  prime"); 
    }

}
 




http://belazy.blog.com/

1 comment:

  1. Good day! This is kind of off topic but I need some
    advice from an established blog. Is it very hard
    to set up your own blog? I'm not very techincal but I can figure things out pretty fast. I'm thinking about making my own but I'm not sure where to begin. Do you have any tips or suggestions? Many thanks

    Here is my site :: visit here

    ReplyDelete

Your feedback may help others !!!

Facebook comments