Tech Number
✹ A Tech Number has an even number of digits. If the number is split into two equal halves. then the square of the sum of these halves is equal to the number itself.
For Example: Input : 2025
Total
Digits : 4
1st Half
: 20
2nd Half : 25
Sum
: 20 + 25 = 45
Square : 45 X 45 = 2025
Output : It is a Tech Number
Few Example of Tech Numbers are
: 81, 2025, 3025, 9801, 494209, 998001
import
java.util.Scanner;
public class Tech_Number
{
public static void main(String args[] )
{
int n,num,ld,rd,c=0,sq=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n; //Copy the value of n in num variable
//Count the Number of Digit
while(num>0)
{
c++;
num=num/10;
}
if(c%2==0) //Check the Number of Digits are Even or Odd
{
rd=n%(int)Math.pow(10,c/2); //Store the Right Half of the Number
ld=n/(int)Math.pow(10,c/2); //Store the Left Half of the Number
sq =(int)Math.pow((ld+rd),2); //Square after adding Left & Right Half of the Digit
if (n == sq) //checking Tech Number
System.out.println("Tech Number");
else
System.out.println("Not a Tech Number");
}
else
System.out.println("Not a Tech Number");
}
}
public class Tech_Number
{
public static void main(String args[] )
{
int n,num,ld,rd,c=0,sq=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n; //Copy the value of n in num variable
//Count the Number of Digit
while(num>0)
{
c++;
num=num/10;
}
if(c%2==0) //Check the Number of Digits are Even or Odd
{
rd=n%(int)Math.pow(10,c/2); //Store the Right Half of the Number
ld=n/(int)Math.pow(10,c/2); //Store the Left Half of the Number
sq =(int)Math.pow((ld+rd),2); //Square after adding Left & Right Half of the Digit
if (n == sq) //checking Tech Number
System.out.println("Tech Number");
else
System.out.println("Not a Tech Number");
}
else
System.out.println("Not a Tech Number");
}
}
No comments