Sunday, July 12, 2020

Write a program to input a number and print all Digit in Words of a number?(123==one two three)

48)   Write a program to input a number and print all Digit in Words of a number?(123==one two three)

import java.util.*;
public class Digit_in_words_7
{
    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 p = a;
          String s = "";
          int c = 0;
          while(p>0)
          {
          p=p/10;
          c++;
          }
          int x = (int)Math.pow(10,(c-1));
          System.out.print(a+" = "); 
          while(k>0)
          {
              int d = k/x;
              k=k%x;
              x=x/10;
              if(d==1)
              {
                  s = "One";
              }
              else if(d==2)
              {
                  s = "Two";
              }
              else if(d==3)
              {
                  s = "Three";
              }
              else if(d==4)
              {
                  s = "Four";
              }
              else if(d==5)
              {
                  s = "Five";
              }
              else if(d==6)
              {
                  s = "Six";
              }
              else if(d==7)
              {
                  s = "Seven";
              }
              else if(d==8)
              {
                  s = "Eight";
              }
              else if(d==9)
              {
                  s = "Nine";
              }
              System.out.print(s+" "); 
          }
        }
}

Output :  

digit-in-words


Write a program to input a number and find & print the Middle Digit of the number, if does not exist find & print the average of middle digits? (33125==1,  8974==9+7=16/2=8)



Write a program to input a number and find & print the Middle Digit of the number, if does not exist find & print the average of middle digits? (33125==1, 8974==9+7=16/2=8)

47)   Write a program to input a number and find & print the Middle Digit of the number, if does not exist find & print the   average of middle digits? (33125==1,  8974==9+7=16/2=8)

import java.util.*;
public class Middle_digit
{
     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)
      {
          c++;
          k=k/10;
      }
      if(c%2==0)
      {
          int x = (int)Math.pow(10,((c/2)-1));
          int t = a/x;
          int m = t%10;
          t=t/10;
          int n = t%10;
          System.out.println("Avereage of middle digits of a number = "+(m+n)/2.0);
      }
      else
      {
          int x = (int)Math.pow(10,(c/2));
          int t = a/x;
          System.out.println("Middle digit of a number = "+t%10);
      }
    }
}
Output :

middle-digit-of-a-number

 Output :

middle-digit-of-a-number


Write a program to input a number and check whether it is Special two digit number or not?(59, 5+9=14, 5*9=45, sum=14+45=59)



Write a program to input a number and check whether it is Special two digit number or not?(59, 5+9=14, 5*9=45, sum=14+45=59)

46)  Write a program to input a number and check whether it is Special two digit number or not?(59, 5+9=14, 5*9=45, sum=14+45=59)

import java.util.*;
public class Special_two_digit
{
   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 = 1;
      int k = a;
      if(a>9&&a<100)
      {
          while(k>0)
          {
              int d = k%10;
              s=s+d;
              p=p*d;
              k=k/10;
          }
          int n = s+p;
          if(n==a)
          {
              System.out.println("Entered number is a SPECIAL TWO DIGIT NUMBER ");
          }
          else
          {
              System.out.println("Entered number is not a SPECIAL TWO DIGIT NUMBER");
          }
      }
      else
      {
        System.out.println("Entered number is not a SPECIAL TWO DIGIT NUMBER");
      }
    }
}
 Output :

special-two-digit-number


   Write a program to input a number and find the sum of First and Last digit of this number?(2784=2+4=6first and last digit sum) 


Wednesday, July 8, 2020

Write a program to input a number and find the sum of First and Last digit of this number?(2784=2+4=6first and last digit sum)

45)  Write a program to input a number and find the sum of First and Last digit of this number?(2784=2+4=6first and last digit sum)


import java.util.*;
public class First_last_digit_sum
{
   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;
      int c = 0;
      while(p>0)
      {
          p=p/10;
          c++;
      }
      int x = (int)Math.pow(10,(c-1));
      int l = a/x;
      int f = a%10;
      int s = l+f;
      System.out.println("SUM of FIRST and LAST digit of a entered number = "+s);
    }
}

Output :  

sum-of-first-and-last-digit-of-a-number


Write a program to input a number and find the Sum and Count the all digit of this number.(2784=2+7+8+4=21…no. of digit=4)


Write a program to input a number and find the Sum and Count the all digit of this number.(2784=2+7+8+4=21…no. of digit=4)

44)   Write a program to input a number and find the Sum and Count the all digit of this number.  (2784=2+7+8+4=21…no. of digit=4)

import java.util.*;
public class sum_count_digits
{
   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;
      int s = 0;
      while(a>0)
      {
          int d = a%10;
          c++;
          s=s+d;
          a=a/10;
      }
      System.out.println("SUM of all digits of a entered number = "+s);
      System.out.println("Number of digits in a entered number = "+c);
    }
}
 

 Output : 


Write a program to input a number and find it’s all Prime Factor and print it?(12==2,2,3….all factors are prime)

43)  Write a program to input a number and find it’s all Prime Factor and print it?(12==2,2,3….all    factors are prime)

import java.util.*;
public class Prime_factor
{
    public static void main(String args[ ])
   {
      Scanner sc = new Scanner (System.in);
      System.out.println("Enter a number");
      int a = sc.nextInt();
      int t = a/2;
      System.out.print("PRIME FACTOR of "+a+" = ");
 if(a==1)
 {
   System.out.println(a);
 } 
     
      for(int i = 2;i<=t;)
      {
          if(a%i==0)
          {
             System.out.print(i+" ");
             a=a/i;
          }
          else
          {
             i++;
          }
      }
 
   }
   }

Output : 

Monday, July 6, 2020

Write a program to input a number and find the Primorial of this number? (6= 2, 3, 5 =2*3*5=30)

42)   Write a program to input a number and find the Primorial of this number? (6= 2, 3, 5        à2*3*5=30)

import java.util.*;
public class Primorial
{
   public static void main(String args[ ])
   {
      Scanner sc = new Scanner (System.in);
      System.out.println("Enter a number");
      int a = sc.nextInt();
      int p=1;
      for(int i=2;i<=a;i++)
      {
        int c = 0;
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            c++;
        }
        if(c==2)
        {
            p = p*i;
        }                 
      }
      System.out.println("PRIMORIAL of "+a+" = "+p);
    }
}

output :  


 jhvghvgk ;nkjn ,nkjhj