Java Program to Check Tech Number

Write a Java program to check tech numbers 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 number, then it is a Tech number. So, in this Java example, first, we count the total numbers of digits, and if it is even then, we divide them into two half. Next, we find the sum of those two half 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 Java 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 to Check Tech 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 a Tech Number");
		}
	}
	
	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 to Check Tech Number = 2025
2025 is a Tech Number


Please Enter Number to Check Tech Number = 2050
2050 is Not a Tech Number

This Java program prints the tech numbers 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 Techn 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 +  " is a Tech Number");
			}
		}
	}
}
Enter Tech Numbers Start and End Range = 1 10000
The List of Techn Numbers from 1 to 10000
1 is a Tech Number
2025 is a Tech Number
3025 is a Tech Number
9801 is a Tech Number
10000 is a Tech Number

It is another way to print the tech numbers from 1 to N in Java.

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 Tech Numbers 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 +  " is a Tech Number");
			}
		}
	}
	
	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 Tech Numbers Start and End Range = 2 10000
The List of Techn Numbers from 2 to 10000
81 is a Tech Number
2025 is a Tech Number
3025 is a Tech Number
9801 is a Tech Number