A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of these halves is equal to the number itself. Write a program to check tech numbers.
Example -
Input = 3025
(30+25)^2
=55^2
=3025
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Demo
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int k=n,c=0,f=0,fs=0,ls=0,t=0,num=0;
while(k>0)
{
c=c+1;
k=k/10;
}
if(c%2==0)
{
c=c/2;
f=(int)Math.pow(10,c);
fs=n%f;
ls=n/f;
t=fs+ls;
num=(int)Math.pow(t,2);
if(num==n)
System.out.println("Tech Number");
else
System.out.println("Not a Tech Number");
}
else
{
System.out.println("Not a Tech Number");
}
}
}
Example -
Input = 3025
(30+25)^2
=55^2
=3025
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Demo
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int k=n,c=0,f=0,fs=0,ls=0,t=0,num=0;
while(k>0)
{
c=c+1;
k=k/10;
}
if(c%2==0)
{
c=c/2;
f=(int)Math.pow(10,c);
fs=n%f;
ls=n/f;
t=fs+ls;
num=(int)Math.pow(t,2);
if(num==n)
System.out.println("Tech Number");
else
System.out.println("Not a Tech Number");
}
else
{
System.out.println("Not a Tech Number");
}
}
}