Tuesday, June 30, 2020

Write a program to input two integers and check whether it’s Tweens Prime or not? (3,5 two Prime numbers which contain difference between two Primes is 2)

38)  Write a program to input two integers and check whether it’s Twins Prime or not? (3,5 two   Prime numbers which contain difference between two Primes is 2)

import java.util.*;

public class Tweens_prime

{

    public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter two numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int co = 0;

        int c = 0;

        for(int i=1;i<=a;i++)

        {

            if(a%i==0)

            c++;

        }

        for(int i=1;i<=b;i++)

        {

            if(b%i==0)

            co++;

        }

        if(co==2&&c==2&&(a-b==2||a-b==-2))

        {

            System.out.println("Entered numbers are TWEENS PRIME ");

        }

        else

        {

            System.out.println("Entered numbers are not TWEENS PRIME ");

        }

    }

}

Monday, June 29, 2020

Write a program to input a number and check whether it is Mersenne Prime Number or not? (A number is said to be Mersenne prime number if it is Mersenne and Prime both.)

37)   Write a program to input a number and check whether it is Mersenne Prime Number or not? (A number is said to be   Mersenne prime number if it is Mersenne and Prime both.)

import java.util.*;
public class Mersenne_prime_6
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            c++;
        }
        double p = a+1;
        while(p>1.0)
        {
            p=p/2.0;
        }
        if(p==1&&c==2)
        {
            System.out.println("Entered number is a MERSENNE PRIME");
        }
        else
        {
            System.out.println("Entered number is not a MERSENNE PRIME");
        }
    }
}

Sunday, June 21, 2020

Write a program to input a number and check whether it is Mersenne Number or not?(a number is said to be Mersenne number if it is one less than a power of 2, ex- 7 is a Mersenne number 8-1= 7 is the power of two 2^3)

36)  Write a program to input a number and check whether it is Mersenne Number or not?(a number is said to be Mersenne number if it is one less than a power of 2, ex- 7 is a Mersenne number 8-1= 7 is the power of two 23)

import java.util.*;
public class Mersenne_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        double p = a+1;
        while(p>1.0)
        {
            p=p/2.0;
        }
        if(p==0)
        {
            System.out.println("Entered number is a MERSENNE number");
        }
        else
        {
            System.out.println("Entered number is not a MERSENNE number");
        }
    }
}

Write a program to input two numbers and check whether these are Co-Prime or not? (12=1, 2, 3, 4, 6, 12, 25=1, 5, 25 both have one common factor is 1, so it is Co-Prime number.)

35)  Write a program to input two numbers and check whether these are Co-Prime or not?  (12=1, 2, 3, 4, 6, 12,    25=1, 5, 25 both have one common factor is 1, so it is Co-Prime number.)

import java.util.*;
public class COprime_number
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = 0;
        for(int i=1;i<=Math.min(a,b)-1;i++)
        {
            if(a%i==0&&b%i==0)
            c++;
        }
        if(c==1)
        {
            System.out.println("Entered numbers are CO-PRIME number");
        }
        else
        {
             System.out.println("Entered numbers are not CO-PRIME number");
        }
    }
}

Write a program to input a number and check whether it is Composite Number or not?(Num is not Prime, called Composite)

34)  Write a program to input a number and check whether it is Composite Number or not?(Num is not Prime, called Composite)

import java.util.*;
public class Composite_number
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            c++;
        }
        if(c!=2)
        {
            System.out.println("Entered number is a COMPOSITE number");
        }
        else
        {
             System.out.println("Entered number is not a COMPOSITE number");
        }
    }
}

Write a program to input a number and check whether it is Prime Number or not? (Number divided by 1 or itself)

33)  Write a program to input a number and check whether it is Prime Number or not?   (Number divided by 1 or itself)

import java.util.*;
public class Prime_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            c++;
        }
        if(c==2)
        {
            System.out.println("Entered number is a PRIME number");
        }
        else
        {
             System.out.println("Entered number is not a PRIME number");
        }
    }
}

Write a program to input a number and check whether it is Deficient Number or not?(8=1+2+4=7, (sum)<(num))

 32)  Write a program to input a number and check whether it is Deficient Number or not?       (8=1+2+4=7, sum<number)

import java.util.*;
public class Deficient_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            s=s+i;
        }
        if(s<a)
        {
            System.out.println("Entered number is a DEFICIENT number");
        }
        else
        {
            System.out.println("Entered number is not a DEFICIENT number");
        }
    }
}

Write a program to input a number and check whether it is Abundant Number or not? (18= 1+2+3+6+9=21, sum>number)

31)  Write a program to input a number and check whether it is Abundant Number or not? (18= 1+2+3+6+9=21, sum>number)

import java.util.*;
public class Abundant_number
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            s=s+i;
        }
        if(s>a)
        {
            System.out.println("Entered number is a ABUNDANT number");
        }
        else
        {
            System.out.println("Entered number is not a ABUNDANT number");
        }
    }
}

Write a program to input a number and check whether it is Perfect Number or not?(6=factor=1,2,3 =1+2+3=6 , sum=number)

30)  Write a program to input a number and check whether it is Perfect Number or not?(6=factor=1,2,3 =1+2+3=6 , sum=number)

import java.util.*;
public class perfect_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            c=c+i;
        }
        if(c==a)
        {
            System.out.println("Entered number is a PERFECT number");
        }
        else
        {
            System.out.println("Entered number is not a PERFECT number");
        }
    }
}

Write a program to find the Factors or all Divisors of number? (6..fector…(1,2,3,6) )

29)  Write a program to find the Factors or all Divisors of number? (6..fector…(1,2,3,6) )

import java.util.*;
public class Factors
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        System.out.print("Factors of "+a+" = ");
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            System.out.print(i+" ");
        }
    }
}

Write a program to print the Table of a number?

28)       Write a program to print the Table of a number?

import java.util.*;
public class Table
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        System.out.println("\nTABLE of "+a);
        for(int i =1;i<=10;i++)
        {
            System.out.println(a+"x"+i+" = "+a*i);
        }
    }
}

Write a program to print the Factorial of a number? (5! = 5*4*3*2*1=120)

27)   Write a program to print the Factorial of a number? (5! = 5*4*3*2*1=120)

import java.util.*;
public class Factorial
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s =1;
        for(int i =1;i<=a;i++)
        {
            s=s*i;
        }
        System.out.println("Factorial of "+a+" = "+s); 
    }
}

Write a program to read a number having more than 5 digits and print whether the given number is Divisible by 11 or not.( A number is divisible by 11 if and only if the difference of the sums of digits at odd positions and even positions is either zero or divisible by 11)

26)  Write a program to read a number having more than 5 digits and print whether the given number is Divisible by 11 or  not.( A number is divisible by 11 if and only if the difference of the sums of digits at odd positions and even positions is either zero or divisible by 11)

import java.util.*;
public class number_divisible_by_11
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int m = a;
        int k = a;
        int e = 0,o = 0;
        int c =0;
        while(k>0)
        {
            k=k/10;
            c++;
        }
        if(c>5)
        {
            while(m>0)
            {
                int d = m%10;
                if(c%2==0)
                {
                    e=e+d;
                }
                else
                {
                    o=o+d;
                }
                c--;
                m=m/10;
            }
            if
            ((o%11==0&&e%11==0)||o-e==0)
            {
              if(a%11==0)
              {
                  System.out.println(a+" is divisible by 11");
              }
              else
              {
                  System.out.println(a+" is not divisible by 11");
              }
            }
            else
            {
                  System.out.println(a+" is not divisible by 11");
            }
        }
        else
        {
                  System.out.println(a+" is not divisible by 11");
        }
    }
}

Write a program to input a number and check whether it is Pronic ( heteromecic ) Number or not?(which is the product of two consecutive integers, that is, n*(n+1) , 110k=(int) Math.sqrt (110), k*(k+1)=110)

25)  Write a program to input a number and check whether it is Pronic ( heteromecic ) Number or not?(which is the product of two consecutive integers, that is, n*(n+1) , 110,k=(int) Math.sqrt (110), k*(k+1)=110

import java.util.*;

public class pronic_number

{

    public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter a number");

        int a = sc.nextInt();

        int c = (int)Math.sqrt(a);

        int d = c*(c+1);

        if(d==a)

        {

            System.out.println(a+" is a PRONIC number");

        }

        else

        {

            System.out.println(a+" is not a PRONIC number");

        }

    }

}

Write a program to input a number and check whether it is Sunny Number or not?(24 , 24+1=25 is a perfect square, so 24 is a sunny number)

24)  Write a program to input a number and check whether it is Sunny Number or not?(24 , 24+1=25 is a perfect square, so 24 is a sunny number)

import java.util.*;
public class Sunny_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        double a = sc.nextInt();
        double p = a+1;
        double b = Math.sqrt(p);
        int c = (int)b;
        if(b==c)
        {
            System.out.println(a+" is a SUNNY number");
        }
        else
        {
             System.out.println(a+" is not a SUNNY number");
        } 
    }
}

Write a program to input a number and check whether it is Perfect Cubes Number or not? (27 cubes of 3, 64 cubes of 4)

23)  Write a program to input a number and check whether it is Perfect Cubes Number or     not? (27 cubes of 3, 64 cubes of 4)

import java.util.*; 
public class Perfect_cube
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        double a = sc.nextInt();
        double b = Math.cbrt(a);
        int c = (int)b;
        if(b==c)
        {
            System.out.println("Entered number is a PERFECT CUBE number");
        }
        else
        {
             System.out.println("Entered number is not a PERFECT CUBE number");
        } 
    }
}

Write a program to input a number and check whether it is Perfect Square Number or not? (16, 25, 36…etc.)

22)  Write a program to input a number and check whether it is Perfect Square Number or    not? (16, 25, 36…etc.)

import java.util.*;
public class Perfect_Square_number_5
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        double a = sc.nextInt();
        double b = Math.sqrt(a);
        int c = (int)b;
        if(b==c)
        {
            System.out.println("Entered number is a PERFECT SQUARE number");
        }
        else
        {
             System.out.println("Entered number is not a PERFECT SQUARE number");
        } 
    }
}

Write a program to input a number and check whether it is Beast Number or not? (a number contain 666 in the last)

21)  Write a program to input a number and check whether it is Beast Number or not? (a   number contain 666 in the last)

import java.util.*;
public class Beast_number_5
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int m = a%1000;
        if(m==666)
        {
            System.out.println("Entered number is a BEAST number");
        }
        else
        {
            System.out.println("Entered number is not a BEAST number");
        }
    }
}

Write a program to input a numbers and check whether it is Fizz or Buzz or FizzBuzz. (n%3=0,fizz|n%5=0,buzz|n%15=0,fizz buzz)

20)  Write a program to input a numbers and check whether it is Fizz or Buzz or FizzBuzz. (n%3=0,fizz|n%7=0,buzz|(n%7=0&n%3=0,fizz buzz))

import java.util.*;
public class Fizz_buzz_fizzbuzz_5
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        String s = "";
        if(a%3==0)
        {
            s = "FIZZ";
        }
        else if(a%7==0)
        {
            s = "BUZZ";
        }
        else if(a%7==0&&a%3==0)
        {
            s = "FIZZBUZZ";
        }
        else
        {
            s = "nor FIZZ,BUZZ or FIZZBUZZ";
        }
        System.out.println("Entered number is "+s);
    }
}

Write a program to input a number and find the number is Positive, Negative or Neutral using conditional operator.

19)  Write a program to input a number and find the number is Positive, Negative or    Neutral using conditional operator.

import java.util.*;
public class positive_negative_neutral_without_if_5
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        String k = (a<0)?"negative":(a>0)?"positive":"neutral";
        System.out.println("Entered number is "+k);
    }
}

Write a program to input numbers and find the arithmetic Mean of these numbers? ( [a+b]/2 )

17)  Write a program to input numbers and find the arithmetic Mean of these numbers? (     [a+b]/2  )

import java.util.*;
public class Arthemetic_mean_5
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        double a = sc.nextInt();
        double b = sc.nextInt();
        double d = (a+b)/2.0;
        System.out.println("Arithmetic mean = "+d);
    }
}

Sunday, June 7, 2020

Write a program to input a number and check whether it is Leap Year or not?

16)  Write a program in java to input a number and check whether it is Leap Year or not?( A year contain 366 days called leap year, century year divided by 400 and normal year divided by 4)

import java.util.*;
public class Leap_year_5
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a year");
        int a = sc.nextInt();
        if(a%4==0||a%400==0)
        {
            System.out.println(a+" is a leap year");
        }
        else
        {
            System.out.println(a+" is not a leap year");
        }
    }
}

Write a program to input two numbers and check whether it is Even or Odd without using if else.

15)  Write a program in java to input two numbers and check whether it is Even or Odd     without using if else.

import java.util.*;
public class even_odd_without_ifelse
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        String s = (a%2==0)?"EVEN":"ODD";
        System.out.println("Entered number is "+s);
    }
}

Friday, June 5, 2020

Write a program in java to find Smallest Number in three number using conditional operator.

14)  Write a program in java to find Smallest Number in three number using   conditional operator.

import java.util.*;
public class Smaller_in_three_using_conditional_operator
{ public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter three numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = (a<b) ? (a<c)?a:c : (b<c)?b:c ;
        System.out.println("Smaller num = "+d);
    }
}

Write a program in java to find Greatest Number in three number using conditional operator.

13)   Write a program in java to find Greatest Number in three number using       conditional operator.

import java.util.*;

public class greater_in_three_using_conditional_operator

{

    public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter three numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int c = sc.nextInt();

        int d = (a>b)? (a>c)?a:c : (b>c)?b:c ;

        System.out.println("Greater num = "+d);

    }

}

Write a program in java to find Smallest Number in three number using if else statement.

12)  Write a program in java to find Smallest Number in three number using if else statement.

import java.util.*;

public class Smaller_in_three_using_if_else

{

     public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter three numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int c = sc.nextInt();

        if(a<b&&a<c)

        {

             System.out.println("Smaller number = "+a);

        }

        else if(b<a&&b<c)

        {

            System.out.println("Smaller number = "+b);

        }

        else

        {

            System.out.println("Smaller number = "+c);

        }

    }

}


Write a program in java to find Greatest Number in three number using if else statement.

11)  Write a program in java to find Greatest Number in three number using if         else statement.

import java.util.*;
public class Greater_in_three_using_if_else
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter three numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a>b&&a>c)
        {
             System.out.println("Greater number = "+a);
        }
        else if(b>a&&b>c)
        {
            System.out.println("Greater number = "+b);
        }
        else
        {
            System.out.println("Greater number = "+c);
        }
    }

}


Write a program in java to input a number and check whether it is Buzz Number or not?(n%10==7 ||n%7==0)

10)  Write a program in java to input a number and check whether it is Buzz Number or not?(n%10==7 ||n%7==0)

import java.util.*;
public class Buzz_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a numbers");
        int a = sc.nextInt();
        if(a%10==7||a%7==0)
        {
            System.out.println("Entered number is a buzz number ");
        }
        else
        {
             System.out.println("Entered number is not a buzz number ");
        }
    }
}

Write a program in java to input a number and check whether it is Even or Odd?

9)  Write a program in java to input a number and check whether it is Even or Odd?

import java.util.*;
public class Even_Odd
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a numbers");
        int a = sc.nextInt();
        if(a%2==0)
        {
            System.out.println("Entered numbeer is even");
        }
        else
        {
            System.out.println("Entered numbeer is odd");
        }
    }
}

Thursday, June 4, 2020

Write a program in java to input two numbers and find the Smaller Number using conditional operator.

8)  Write a program in java to input two numbers and find the Smaller Number using conditional operator.

import java.util.*;
public class Smaller_using_conditional_operator
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = (a<b)?a:b;
        System.out.println("Smaller num = "+c);
    }
}

Write a program in java to input two numbers and find the Greater Number using conditional operator.

7)  Write a program in java to input two numbers and find the Greater Number using conditional operator.

import java.util.*;
public class greater_using_conditional_operator
{
    public static void main( String args [ ] )
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = (a>b)?a:b;
        System.out.println("Greater num = "+c);
    }
}

Write a program in java to input two numbers and find the Smaller Number using if else.

6)  Write a program in java to input two numbers and find the Smaller Number using if else.

import java.util.*;
public class Smaller_using_if_else
{
    public static void main( String args[ ] )
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b)
        {
             System.out.println("Smaller number = "+a);
        }
        else
        {
            System.out.println("Smaller number = "+b);
        }
    }
}

Write a program in java to input two numbers and find the Greater Number using if else.

5)  Write a program in java to input two numbers and find the Greater Number using if else.

import java.util.*;
public class Greater_using_if_else
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b)
        {
            System.out.println("Greater number = "+a);
        }
        else
        {
            System.out.println("Greater number = "+b);
        }
    }
}

Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

4)  Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

public class positive_negative_neutral
{
   public static void main(int a)
   {
       if(a>0)
       {
           System.out.println("positive");
       }
       else if(a<0)
       {
           System.out.println("Negative");
       }
       else if(a==0)
       {
           System.out.println("Neutral");
        }
    }
}

Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

3)  Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

public class Swaping_without_using_third_var
{
    public static void main(int a,int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        a = a + b;
        b = a - b;
a = a - b;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}


Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

2)  Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

public class Swaping_using_third_var
{
    public static void main(int a, int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        int p = a;
        a = b;
        b = p;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}

 jhvghvgk ;nkjn ,nkjhj