Showing posts with label java programs. Show all posts
Showing posts with label java programs. Show all posts

Sunday, June 21, 2020

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 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 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);

    }

}

 jhvghvgk ;nkjn ,nkjhj