8 comments:

  1. import java.util.Scanner;

    class Test{

    public static void main(String ar[])
    {

    Scanner sc=new Scanner(System.in);
    double num,count=0;
    System.out.println("Enter Number");
    num=sc.nextDouble();

    for(int i=1;i<=num;i++){
    if(num%i==0)
    count++;
    }

    if(count==2)
    System.out.println("Prime Number");
    else
    System.out.println("Not a Prime Number");


    }
    }

    ReplyDelete
  2. import java.util.Scanner;

    class Test
    {

    public static void main(String ar[])
    {

    int i=2,flag=0,number;
    System.out.print("Enter number: ");
    Scanner w=new Scanner(System.in);
    number=w.nextInt();
    while(i<number)
    {
    if(number%i==0)
    flag=1;
    i++;
    }
    if(flag!=1)
    {
    System.out.print(number+" is a prime number.");
    }
    else
    System.out.print(number+" is not a prime number.");
    }
    }

    ReplyDelete
  3. public class prime
    {
    public static void main(String args[])
    {
    boolean test=false;
    int n=Integer.parseInt(args[0]);
    for(int i=2;i1)
    {

    System.out.print("\n entered number is prime");
    }
    else
    {
    System.out.print("\n entered number is not prime");
    }
    }
    }

    ReplyDelete
  4. import java.util.Scanner;
    class Prime
    {
    public static void main(String Args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the number");
    int num=sc.nextInt();
    int c=0;
    for(int i=1;i<=num;i++)
    {
    if(num%i==0)
    c++;
    }
    if(c==2)
    System.out.println("it is a prime number");
    else
    System.out.println("it is not a prime number");
    }
    }

    ReplyDelete
  5. import java.util.Scanner;
    public class prime {
    public static void main(String args[])
    {
    Scanner scan = new Scanner(System.in);
    double num;
    System.out.println("enter the number");
    num = scan.nextDouble();
    boolean flag = false;
    for(int i=2;i<=num/2;i++)
    {
    if(num%i==0)
    { flag = true;
    break;
    }
    }
    if(!flag)
    System.out.println("the number is prime");
    else
    System.out.println("the number is not prime");
    }
    }

    ReplyDelete
  6. package forloop;
    import java.util.*;
    public class Primenumber
    {
    public static void main(String args[])
    {
    int i,n,count=0;
    System.out.println("enter number");
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    for(i=2;i<=n/2;i++)
    {
    if(n%i==0)
    {
    count=1;
    break;
    }
    }
    if(count==0)
    System.out.println("prime number "+n);
    else
    System.out.println("not a prime number "+n);
    }
    }

    ReplyDelete
  7. import java.util.Scanner;
    class Prime{
    public static void main(String ar[]){
    Scanner obj=new Scanner(System.in);
    int num,i;
    System.out.println("enter the value of number");
    num=obj.nextInt();
    for(i=2;i<=num/2;i++){
    if(num%i==0){
    System.out.println("not prime");

    }
    else{
    System.out.println("prime");
    break;}
    }
    }
    }

    ReplyDelete
  8. import java.util.Scanner;

    class PrimeNumbers{

    public static void main(String ar[]){


    Scanner scan=new Scanner(System.in);
    int num,temp=0;
    System.out.println("Enter number");
    num=scan.nextInt();

    for(int i=2;i<=num;i++){
    if(num%i==0){
    temp=1;
    break;
    }
    }
    if(temp==1){
    System.out.println("No. is not Prime");

    }else{
    System.out.println("No. is Prime");
    }


    }


    }

    ReplyDelete