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 generate and print all four digits 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
{
int fs=0,ls=0,t=0,num=0;
for(int i=1000;i<=9999;i++)
{
fs=i%100;
ls=i/100;
t=fs+ls;
num=(int)Math.pow(t,2);
if(num==i)
System.out.println("Tech Number"+i);
}
}
}
Output=
2025
3025
9801
https://amzn.to/2HtcH2h
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
{
int fs=0,ls=0,t=0,num=0;
for(int i=1000;i<=9999;i++)
{
fs=i%100;
ls=i/100;
t=fs+ls;
num=(int)Math.pow(t,2);
if(num==i)
System.out.println("Tech Number"+i);
}
}
}
Output=
2025
3025
9801
https://amzn.to/2HtcH2h
No comments:
Post a Comment
any problem in any program comment:-