icse-promo

Question

A tech number has a even number of digits if the number is split in two equal halves , then the square of sum of these two halves is equal to the number itself. Write a program to generate and print all 4 digit tech numbers:

				
					Example:
Consider the number 3025
Square of sum of the halves of 3025
= (30 + 25)²
= (55)²
3025 is a tech number
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					public class program9
{
	public static void main(String[]args)
	{

		int firstHalf=0,secondHalf=0,sumOfSquare=0,i=0;
		for(i=1000;i<=9999;i++) 
		{
		        /* dividing number into two half*/
				firstHalf=i/100;
				secondHalf=i%100;
				sumOfSquare=(int)Math.pow((firstHalf+secondHalf),2);
				if(sumOfSquare==i)
				{
					System.out.print(i+" ");
		        }
		}
	}
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *