In this tutorial, we will learn about Tech numbers and create a Java program to check for Tech numbers. We will see two java examples on Tech Numbers with Java Programming.
What is Tech Number?
A number is said to be Tech Number if the number is an even digit number and is equally divided into two halves. After that add the equally divided two halves and find the sum of that number. If we get the original number itself then it is a Tech Number.
Example: 3025, 2025, etc.
2025 => 20 + 25 => (55)2 => 3025, hence Tech Number.

Let us go through the program, we will write two different programs:
- Check for the Tech number in java.
- print all the tech numbers within a given range.
Java program and check whether the Number is Tech or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import java.util.Scanner; public class TechNumber { public static void main(String[] args) { int n, num, leftNumber, rightNumber, digits = 0, sumSquare = 0; Scanner sc = new Scanner(System.in); System.out.print("Enter the number: "); n = sc.nextInt(); num = n; while (num > 0) { digits++; num = num / 10; } //check for even or odd if (digits % 2 == 0) { num = n; leftNumber = num % (int) Math.pow(10, digits / 2); num = num / (int) Math.pow(10, digits / 2); rightNumber = num; sumSquare = (leftNumber + rightNumber) *(leftNumber + rightNumber); //cheks with original Number and print the result if (n == sumSquare) { System.out.println(n + " is a Tech Number"); } else { System.out.println(n + " is not a Tech Number"); } } else //by default Not Tech because the digits are odd { System.out.println(n + " Not Tech Number"); } } } |
Output:
Enter the number: 3025
3025 is a Tech Number
//Another Output
Enter the number: 1045
1045 is not a Tech Number
Java Program to find all Tech Number in a given Range
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import java.util.Scanner; public class TechNumberEg { private static boolean isTechFunc(int number) { // declare variables int n = number, count = 0, firstHalf = 0; int lastHalf = 0, sum = 0; //counting number of digits while (n != 0) { n /= 10; count++; } // for the digit to be odd if (count % 2 != 0) return false; //dividing in two firstHalf = number / (int) Math.pow(10, count / 2); lastHalf = number % (int) Math.pow(10, count / 2); //sum of the two halves sum = firstHalf + lastHalf; // squaring the sum and check with original if (sum *sum == number) return true; return false; } public static void main(String[] args) { int n, num, lrRange, upRange, digits = 0, sumSquare = 0; Scanner sc = new Scanner(System.in); System.out.print("Enter the lower range: "); lrRange = sc.nextInt(); System.out.print("Enter the uppper range: "); upRange = sc.nextInt(); System.out.println("The Tech Numbers between " + lrRange + " and " + upRange + " are: "); for (int i = lrRange; i <= upRange; i++) { if (isTechFunc(i)) System.out.print(i + " "); } } } |
Output:
Enter the lower range:: 1
Enter the uppper range:: 10000
The Tech Numbers between 1 and 10000 are:
81 2025 3025 9801