Sunday, June 21, 2020

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

        }

    }

}

 jhvghvgk ;nkjn ,nkjhj