Java Program to Check Tech Number

Write a Java program to check the tech number or not. For example, if a number has an even number of digits, it is exactly divided into two parts, and the square of the sum of those two parts equals the actual, then it is a Tech number. So, in this example, first, we count the total number of digits, and if it is even, then we divide them into two halves.

Next, we find the sum of those two halves and perform the square of the result. The If statement checks whether the actual number equals the square, then it is a tech number.

package NumPrograms;

import java.util.Scanner;

public class TechNumber1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Please Enter Number to Check Tech Number = ");
		int tNum = sc.nextInt();
		
		int temp, firstHalf, secondHalf, Sqsum = 0, count = 0;
		
		for(temp = tNum; temp > 0; temp = temp/10)
		{
			count = count + 1;
		}
		
		if(count % 2 == 0)
		{
			temp = tNum;
			firstHalf  = temp % (int)Math.pow(10,  count /2);
			secondHalf = temp / (int)Math.pow(10,  count /2);
			
			Sqsum = (firstHalf + secondHalf) * (firstHalf + secondHalf);
			
			if(tNum == Sqsum)
			{
				System.out.println(tNum +  " is a Tech Number");
			}
			else
			{
				System.out.println(tNum +  " is Not a Tech Number");
			}
		}
		else 
		{
			System.out.println(tNum +  " is Not a Tech Number");
		}
	}

}
Java Program to Check Tech Number

In this program, the digitCount counts the digits in a number, and the sumOfToHalfs divides the number into two halls and finds the sum of the square of the two half.

package NumPrograms;

import java.util.Scanner;

public class TechNumber2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Please Enter Number = ");
		int tNum = sc.nextInt();
		
		int count = digitCount(tNum);
		
		if(count % 2 == 0 && tNum == sumOfToHalfs(tNum, count))
		{	
			System.out.println(tNum +  " is a Tech Number");
		}
		else 
		{
			System.out.println(tNum +  " is Not");
		}
	}
	
	static int digitCount(int tNum)
	{
		int count = 0;
		for(; tNum > 0; tNum = tNum/10)
		{
			count = count + 1;
		}
		return count;
	}
	
	static int sumOfToHalfs(int tNum, int count)
	{
		int firstHalf, secondHalf, Sqsum = 0; 
	
		firstHalf  = tNum % (int)Math.pow(10,  count /2);
		secondHalf = tNum / (int)Math.pow(10,  count /2);
		
		Sqsum = (firstHalf + secondHalf) * (firstHalf + secondHalf);
		
		return Sqsum;
	}

}
Please Enter Number = 2025
2025 is a Tech Number


Please Enter Number = 2050
2050 is Not

This Java program checks and prints the tech number within a given range.

package NumPrograms;

import java.util.Scanner;

public class TechNumber3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Tech Numbers Start and End Range = ");	
		int start = sc.nextInt();
		int end = sc.nextInt();
		
		int firstHalf, secondHalf, Sqsum = 0;
		
		System.out.println("The List of Tech Numbers from " + start + " to " + end);
		for(int i = start; i <= end; i++)
		{
			firstHalf  = i % 100;
			secondHalf = i / 100;
			Sqsum = (firstHalf + secondHalf) * (firstHalf + secondHalf);
			
			if(i == Sqsum)
			{
				System.out.println(i);
			}
		}
	}
}
Enter Tech Numbers Start and End Range = 1 10000
The List of Tech Numbers from 1 to 10000
1
2025
3025
9801
10000

It is another way to print the tech numbers from 1 to N. Please refer to Java programs.

package NumPrograms;

import java.util.Scanner;

public class TechNumber4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Start and End Range = ");	
		int start = sc.nextInt();
		int end = sc.nextInt();
		
		System.out.println("The List of Techn Numbers from " + start + " to " + end);
		for(int i = start; i <= end; i++)
		{				
			if(i == sumOfToHalfs(i))
			{	
				System.out.println(i);
			}
		}
	}
	
	static int digitCount(int tNum)
	{
		int count = 0;
		for(; tNum > 0; tNum = tNum/10)
		{
			count = count + 1;
		}
		return count;
	}
	
	static int sumOfToHalfs(int tNum)
	{
		int firstHalf, secondHalf, Sqsum = 0; 
		int count = digitCount(tNum);
		
		if(count % 2 == 0)
		{	
			firstHalf  = tNum % (int)Math.pow(10,  count /2);
			secondHalf = tNum / (int)Math.pow(10,  count /2);
		
			Sqsum = (firstHalf + secondHalf) * (firstHalf + secondHalf);
		}
		
		return Sqsum;
	}

}
Enter Start and End Range = 2 10000
The List of Techn Numbers from 2 to 10000
81
2025
3025
9801