Wednesday, August 5, 2020

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 : 




Write a program to input a number in Decimal and convert it Hexadecimal form? (100 in decimal then 64 in hexadecimal, divide by 16)

72)  Write a program to input a number in Decimal and convert it Hexadecimal form? (100 in decimal then 64 in hexadecimal, divide by 16)


import java.util.*;
public class Decimal_to_Hexadeciamal
{
    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;
           String c = "";
           while(a>=1)
           {
               if(a%16<10&&a%16>-1)
               {
                   c=c+(a%16);
               }
               else if(a%16==10)
               {
                   c=c+"A";
               }
               else if(a%16==11)
               {
                   c=c+"B";
               }
               else if(a%16==12)
               {
                   c=c+"C";
               }
               else if(a%16==13)
               {
                   c=c+"D";
               }
               else if(a%16==14)
               {
                   c=c+"E";
               }
               else if(a%16==15)
               {
                   c=c+"F";
               }
               a=a/16;
           }
           int k = c.length();
           System.out.print("Entered number in HEXADECIMAL = ");
           for(int i = k-1;i>=0;i--)
           {
                System.out.print(c.charAt(i));
           }
   }
}

Output : 






Tuesday, August 4, 2020

Write a program to input a number in Decimal and convert it Octal form?( 8 in decimal then 10 in octal, divide by 8)

71)  Write a program to input a number in Decimal and convert it Octal form?( 8 in decimal then 10 in octal, divide by 8)


import java.util.*;
public class Decimal_to_octal
{
    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;
           String c = "";
           while(a>=1)
           {
               c=c+(a%8);
               a=a/8;
           }
           int k = c.length();
           System.out.print("Entered number in OCTAL = ");
           for(int i = k-1;i>=0;i--)
           {
                System.out.print(c.charAt(i));
           }
   }
}

Output : 






Write a program to input a number in Decimal and convert it Binary form?(9 in decimal then 1001 in binary, divide by 2)

70)  Write a program to input a number in Decimal and convert it Binary form?(9 in decimal then 1001 in binary, divide by 2)


import java.util.*;
public class Decimal_to_binary
{
    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;
           String c = "";
           while(a>=1)
           {
               c=c+(a%2);
               a=a/2;
           }
           int k = c.length();
           System.out.print("Entered number in BINARY = ");
           for(int i = k-1;i>=0;i--)
           {
                System.out.print(c.charAt(i));
           }
   }
}


Output : 




Write a program to input a number and check whether it is Emirp Number (Twisted Prime) or not?(13 and its reverse 31,both are prime)

69)  Write a program to input a number and check whether it is Emirp Number (Twisted Prime) or not?(13  and its reverse 31,both are prime)


import java.util.*;
public class Emirp
{
   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 r = 0;
           int c = 0;
           for(int i = 1;i<=a;i++)
           {
                  if(a%i==0)
                  {
                      c++;
                  }
           }
           if(c==2)
           {
              while(k>0)
              {
              int d = k%10;
              r=(r*10)+d;
              k=k/10;
              }
              c=0;
              for(int i = 1;i<=r;i++)
              {
                      if(r%i==0)
                      {
                          c++;
                      }
              }
              if(c==2)
              {
                  System.out.println("Entered number is a EMIRP(TWISTED PRIME) Number");
              }
              else
              {
                  System.out.println("Entered number is not a EMIRP(TWISTED PRIME) Number");
              }
           }
           else
           {
                  System.out.println("Entered number is not a EMIRP(TWISTED PRIME) Number");
           }
   }
}

Output : 


emirp-number

  Write a program to input a number and check whether it is Pal Prime Number or not?(prime and palindrome=131)



Write a program to input a number and check whether it is Pal Prime Number or not?(prime and palindrome=131)

68)   Write a program to input a number and check whether it is Pal Prime Number or not?(prime and palindrome=131)


import java.util.*;
public class pal_prime
{
    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 r = 0;
              int c = 0;
              while(k>0)
              {
              int d = k%10;
              r=(r*10)+d;
              k=k/10;
              }
              if(r==a)
              {
                  for(int i = 1;i<=a;i++)
                  {
                      if(a%i==0)
                      {
                          c++;
                      }
                  }
                  if(c==2)
                  {
                      System.out.println("Entered number is a PAL-PRIME Number");
                  }
                  else
                  {
                      System.out.println("Entered number is not a PAL-PRIME Number");
                  }
              }
              else
              {
                  System.out.println("Entered number is not a PAL-PRIME Number");
              }
   }
}

Output : 




 jhvghvgk ;nkjn ,nkjhj