Friday, July 31, 2020

Write a program to input a number and check whether it is Tech Number or not? (3025= (30+25)^2 = (55)^2 =3025 so it is tech number).

61)  Write a program to input a number and check whether it is Tech Number or not? (3025= (30+25)2 = (55)2 =3025 so it is tech number).


import java.util.*;
public class Tech_number
{
    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++;
              }
              if(c%2==0)
              {
                  int x = (int)Math.pow(10,(c/2));
                  int m = a%x;
                  int n = a/x;
                  int y = (int)Math.pow((m+n),2);
                  if(y==a)
                  {
                      System.out.println("Entered number is a TECH Number");
                  }
                  else
                  {
                      System.out.println("Entered number is not a TECH Number");
                  }
              }
              else
            {
                      System.out.println("Entered number is not a TECH Number");
            }
   }
}

Output : 


No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj