Monday, July 27, 2020

Write a program to find Reverse of any number?(123=321)

55)       Write a program to find Reverse of any number?(123=321)


import java.util.*;
public class Reverse_number
{
    public static void main(String args[ ])
   {
              Scanner sc = new Scanner (System.in);
              System.out.println("Enter a number");
              int k = sc.nextInt();
              int r = 0;
              while(k>0)
              {
              int d = k%10;
              r=(r*10)+d;
              k=k/10;
              }
              System.out.println("REVERSE number = "+r);
   }
}

Output : 


Write a program to input a number and check whether it is Neon Number or not?(9^2 = 81 , 8+1=9 , 9=9)

54)  Write a program to input a number and check whether it is Neon Number or not?(92 = 81 , 8+1=9 , 9=9)


import java.util.*;
public class Neon_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;
          int p = a*a;
          while(p>0)
          {
          int d = p%10;
          s=s+d;
          p=p/10;
          }
          if(a==s)
          {
              System.out.println("Entered number is a NEON number ");
          }
          else
          {
              System.out.println("Entered number is not a NEON number ");
          }
   }
}

Output : 

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

53)  Write a program to input a number and check whether it is Spy Number or not? (123 = 1+2+3 = 6  , 1*2*3 = 6 , 6=6)

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

Output : 

Write a program to input a number and check whether it is Niven Number (Harshad Number) or not? (81=8+1=9,81%9=0)

51)  Write a program to input a number and check whether it is Niven Number (Harshad Number) or not? (81=8+1=9,81%9=0)

import java.util.*;
public class Niven_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;
          int p = a;
          while(p>0)
          {
          int d = p%10;
          s=s+d;
          p=p/10;
          }
          if(a%s==0)
          {
              System.out.println("Entered number is a NIVEN(HARSHAD) number ");
          }
          else
          {
              System.out.println("Entered number is not a NIVEN(HARSHAD) number ");
          }
   }
}

Output :



Write a program to input a numbers and find the frequency of any digit of this number, digit choose by the user. (124443=frequency of 4=3)

50)  Write a program to input a numbers and find the frequency of any digit of this number, digit choose by the user. (124443=frequency of 4=3)


import java.util.*;
public class Frequency_of_a_digit
{
     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("Enter a number of which you need FREQUENCY");
          int b = sc.nextInt();
          int p = a;
          int c = 0;
          while(p>0)
          {
          int d = p%10;
          if(d==b)
          {
          c++;
          }
          p=p/10;
          }
          System.out.println("FREQUENCY of "+b+" in "+a+" = "+c);   
   }
}

Output : 

frequency-of-a-digit-in-number


   Write a program with a special member function to input a multi digit long integer number ( max. 9 digit) and print the following:

1-Total number of Even and Odd digits

2-The Reverse Number

3-Total number of Zero’s present.


Sunday, July 26, 2020

Write a program with a special member function to input a multi digit long integer number ( max. 9 digit) and print the following: 1-Total number of Even and Odd digits 2-The Reverse Number 3-Total number of Zero’s present.

50)  Write a program with a special member function to input a multi digit long integer number ( max. 9 digit) and print the following:
1-Total number of Even and Odd digits
2-The Reverse Number
3-Total number of Zero’s present.


import java.util.*;
public class Menu_driven
{
    public static void main(String args[ ])
   {
         Scanner sc = new Scanner (System.in);
         System.out.println(">>>>...MENU...<<<<");
         System.out.println("Press 1 for number of EVEN and ODD digit");
         System.out.println("Press 2 for REVERSE number");
         System.out.println("Press 3 for TOTAL number of ZERO in a number");
         System.out.println("\nEnter your choice");
         int c = sc.nextInt();
         int e = 0, o = 0;
         switch(c)
         {
              case 1:
              System.out.println("Enter a number (not more then 8 digit)");
              long t = sc.nextInt();
              long w = t, x = 0;
              while(w>0)
              {
                w=w/10;
                x++;
              }
              if(x<=9)
              {
              long r = 0;
              while(t>0)
              {
              long d = t%10;
              t=t/10;
              if(d%2==0)
              {
                  e++;
              }
              else
              {
                  o++;
              }
              }
              System.out.println("Number of ODD digits = "+o);
              System.out.println("Number of EVEN digits = "+e);
              }
              else
              {
                System.out.println("Number NOT EXIST "); 
              }
              break;
              case 2:
              System.out.println("Enter a number (not more then 9 digit)");
              long k = sc.nextInt();
              long q = k, i = 0;
              while(q>0)
              {
                q=q/10;
                i++;
              }
              if(i<=9)
              {
              long r = 0;
              while(k>0)
              {
              long d = k%10;
              r=(r*10)+d;
              k=k/10;
              }
              System.out.println("REVERSE number = "+r);
              }
              else
              {
                System.out.println("Number NOT EXIST "); 
              }
              break;
              case 3:
              System.out.println("Enter a number (not more then 9 digit)");
              long y = sc.nextInt();
              long m=0;
              long h = y, j = 0;
              while(h>0)
              {
                h=h/10;
                j++;
              }
              if(j<=9)
              {
              while(y>0)
              {
              long d = y%10;
              y=y/10;
              if(d==0)
              {
                  m++;
              }
              }
              System.out.println("Total number of ZERO present = "+m);
              }
              else
              {
                System.out.println("Number NOT EXIST "); 
              }
              break;
              default:
              System.out.println("ENVALID CHOICE");
         }
   }
}

Output :


Menu Driven

Write a program to accept a multi digit long integer number(max. 8 digits) and do the following: 

1- Print the Reverse Number. (123…321(reverse))

2-Print the Absolute difference between them.

3- Print Smallest Digit. (7839== smallest digit is 3)           



Write a program to accept a multi digit long integer number(max. 8 digits) and do the following: 1- Print the Reverse Number. (123…321(reverse)) 2-Print the Absolute difference between them. 3- Print Smallest Digit. (7839== smallest digit is 3)

49)       Write a program to accept a multi digit long integer number(max. 8 digits) and do the following: 
1- Print the Reverse Number. (123…321(reverse))
2-Print the Absolute difference between them.
3- Print Smallest Digit. (7839== smallest digit is 3)          


import java.util.*;

public class Menu_driven_7

{

    public static void main(String args[ ])

   {

         Scanner sc = new Scanner (System.in);

         System.out.println(">>>>...MENU...<<<<");

         System.out.println("Press 1 for REVERSE a number");

         System.out.println("Press 2 for ABSOLUTE DIFFERENCE");

         System.out.println("Press 3 for SMALLEST DIGIT of a number");

         System.out.println("\nEnter yopur choice");

         int c = sc.nextInt();

         switch(c)

         {

              case 1:

              System.out.println("Enter a number (not more then 8 digit)");

              long k = sc.nextInt();

              long q = k, i = 0;

              while(q>0)

              {

                q=q/10;

                i++;

              }

              if(i<=8)

              {

              long r = 0;

              while(k>0)

              {

              long d = k%10;

              r=(r*10)+d;

              k=k/10;

              }

              System.out.println("REVERSE number = "+r);

              }

              else

              {

                System.out.println("Number NOT EXIST "); 

              }

              break;

              case 2:

              System.out.println("Enter a number (not more then 8 digit)");

              long a = sc.nextInt();

              long l = a, x = 0;

              while(l>0)

              {

                l=l/10;

                x++;

              }

              if(x<=8)

              {

              long j = a;

              long t = 0;

              while(j>0)

              {

              long d = j%10;

              t=(t*10)+d;

              j=j/10;

              }

              System.out.println("ABSOLUTE difference = "+(a-t));

              }

              else

              {

                System.out.println("Number NOT EXIST "); 

              }

              break;

              case 3:

              System.out.println("Enter a number (not more then 8 digit)");

              long y = sc.nextInt();

              long h = y, j = 0;

              while(h>0)

              {

                h=h/10;

                j++;

              }

              if(j<=8)

              {

              long m = 9;

              while(y>0)

              {

              long d = y%10;

              y=y/10;

              if(d<m)

              {

                  m=d;

              }

              }

              System.out.println("SMALLEST number = "+m);

              }

              else

              {

                System.out.println("Number NOT EXIST "); 

              }

              break;

              default:

              System.out.println("ENVALID CHOICE");

         }

   }

}


Output :

Menu driven
 














 jhvghvgk ;nkjn ,nkjhj