Wednesday, August 5, 2020

Write a program to input a number and check whether it is Adam Number or not? (12^2 =144 , 21^2 = 441 = 144, 144=144 )

79)  Write a program to input a number and check whether it is Adam Number or not?  (122 =144 , 212 = 441 = 144, 144=144 )


import java.util.*;
public class Adam_num
{
    public static void main(String args[ ])
   {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a number");
           int a = sc.nextInt();
           int p = a*a;
           int r = 0;
           while(a>0)
           {
               int d = a%10;
               r=(r*10)+d;
               a=a/10;
           }
           int p1 = r*r;
           r=0;
           while(p1>0)
           {
               int d = p1%10;
               r=(r*10)+d;
               p1=p1/10;
           }
           if(p==r)
           {
               System.out.println("Entered number is a ADAM Number");
           }
           else
           {
               System.out.println("Entered number is not a ADAM Number");
           }
   }
}

Output : 


 


Write a program to input a number and check whether it is Disarium Number or not? (135=1^1+3^2+5^3=1+9+125=135)

78)  Write a program to input a number and check whether it is Disarium Number or not?  (135=11+32+53=1+9+125=135)


import java.util.*;
public class Disarium_num
{
    public static void main(String args[ ])
   {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a number");
           int a = sc.nextInt();
           int k = a;
           int c = 0;
           while(k>0)
           {
               k=k/10;
               c++;
           }
           int r = 0;
           k=a;
           for(int i = c;i>=1;i--)
           {
               int d = k%10; 
               int x = (int)Math.pow(d,i);
               r=r+x;
               k=k/10;
           }
           if(r==a)
           {
               System.out.println("Entered number is a DISARIUM Number");
           }
           else
           {
               System.out.println("Entered number is not a DISARIUM Number");
           }
   }
}

Output : 


 



Write a program to input a number and check whether it is Odious Number or not? (7…binary…111.no. of ones is 3 and it is odd.so it is odious no.)

77)  Write a program to input a number and check whether it is Odious Number or not? (7…binary…111.no. of ones is 3 and it is odd.so it is odious no.)


import java.util.*;
public class Odious_num
{
    public static void main(String args[ ])
   {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a number");
           int b = sc.nextInt();
           int a = b;
           int r = 0;
           String c = "";
           while(a>=1)
           {
               if(a%2==0)
               {
                   c=c+"0";
               }
               else
               {
                   c=c+"1";
               }
               a=a/2;
           }
           int k = c.length();
           for(int i = k-1;i>=0;i--)
           {
               if(c.charAt(i)=='1')
               {
                   r++;
               }
           }
           if(r%2!=0)
           {
               System.out.println("Entered number is a ODIOUS Number");
           }
           else
           {
               System.out.println("Entered number is not a ODIOUS Number");
           }
   }
}

Output : 




Write a program to input a number and check whether it is Evil Number or not? (5...binary...101.no. of ones is 2 and it is even.so it is evil no.)

76)  Write a program to input a number and check whether it is Evil Number or not? (5...binary...101.no. of ones is 2 and it is even.so it is evil no.)


import java.util.*;
public class Evil_num
{
    public static void main(String args[ ])
   {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a number");
           int b = sc.nextInt();
           int a = b;
           int r = 0;
           String c = "";
           while(a>=1)
           {
               if(a%2==0)
               {
                   c=c+"0";
               }
               else
               {
                   c=c+"1";
               }
               a=a/2;
           }
           int k = c.length();
           for(int i = k-1;i>=0;i--)
           {
               if(c.charAt(i)=='1')
               {
                   r++;
               }
           }
           if(r%2==0)
           {
               System.out.println("Entered number is a EVIL Number");
           }
           else
           {
               System.out.println("Entered number is not a EVIL Number");
           }
   }
}

Output : 




Write a program to input a number in Hexadecimal form and convert it decimal form? (64 in Hexadecimal then 100 in decimal, 16^0, 16^1, ….)

75)  Write a program to input a number in Hexadecimal form and convert it decimal form? (64 in Hexadecimal then 100 in decimal, 160, 161, ….)


import java.util.*;
public class Hexadecimal_in_Decimal
{
    public static void main(String args[ ])
  {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a HEXADECIMAL number");
           String b = sc.nextLine();
           int a = b.length();
           int m = 0;
           int r = a-1;
           int c = 0;
           while(m<a)
           {
               char d = b.charAt(r);
               int x = (int)Math.pow(16,m);
               m++;
               if(d=='0')
               {
                   c=c+0*x;
               }
               else if(d=='1')
               {
                   c=c+1*x;
               }
               else if(d=='2')
               {
                   c=c+2*x;
               }
               else if(d=='3')
               {
                   c=c+3*x;
               }
               else if(d=='4')
               {
                   c=c+4*x;
               }
               else if(d=='5')
               {
                   c=c+5*x;
               }
               else if(d=='6')
               {
                   c=c+6*x;
               }
               else if(d=='7')
               {
                   c=c+7*x;
               }
               else if(d=='8')
               {
                   c=c+8*x;
               }
               else if(d=='9')
               {
                   c=c+9*x;
               }
               else if(d=='a'||d=='A')
               {
                   c=c+10*x;
               }
               else if(d=='B'||d=='b')
               {
                   c=c+11*x;
               }
               else if(d=='c'||d=='C')
               {
                   c=c+12*x;
               }
               else if(d=='D'||d=='d')
               {
                   c=c+13*x;
               }
               else if(d=='e'||d=='E')
               {
                   c=c+14*x;
               }
               else if(d=='F'||d=='f')
               {
                   c=c+15*x;
               }
               r--;
           }
           System.out.println(b+" in DECIMAL = "+c);
  }
}


Output : 




Write a program to input a number in Octal form and convert it Decimal form? (10 in octal then 8 in decimal, 8^0, 8^1, ….)

74)  Write a program to input a number in Octal form and convert it Decimal form? (10 in octal then 8 in decimal, 80, 81, ….)


import java.util.*;
public class Octal_to_Decimal
{
    public static void main(String args[ ])
  {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a OCTAL number");
           int b = sc.nextInt();
           int a = b;
           int m = 0;
           int r = 0;
           while(a>0)
           {
               int d = a%10;
               int x = (int)Math.pow(8,m);
               r = r+(x*d);
               m++;
               a=a/10;
           }
           System.out.println(b+" in DECIMAL = "+r);
  }
}

Output :


 
 


Write a program to input a number in Binary form and convert it Decimal form? (1010 in binary then 10 in decimal, 2^0 , 2^1……)

73)  Write a program to input a number in Binary form and convert it Decimal form? (1010 in binary then 10 in decimal, 20 , 21……)


import java.util.*;
public class Binary_to_decimal
{
  public static void main(String args[ ])
  {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a BINARY number");
           int b = sc.nextInt();
           int a = b;
           int m = 0;
           int r = 0;
           while(a>0)
           {
               int d = a%10;
               int x = (int)Math.pow(2,m);
               r = r+(x*d);
               m++;
               a=a/10;
           }
           System.out.println(b+" in DECIMAL = "+r);
  }
  }


Output : 




 jhvghvgk ;nkjn ,nkjhj