C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Tech Number Program - Java Programs

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:
Consider the number 3025.
Square of sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.

Type 1 Program - Without Function

import java.util.Scanner; class Tech{ public static void main(String[] args){ Scanner in = new Scanner(System.in); for(int i = 1000; i <= 9999; i++){ int a = i / 100; int b = i % 100; int s = (a + b) * (a + b); if(i == s) System.out.print(i + " "); } } }

Output

 
 OUTPUT : 
2025 3025 9801  

Type 2 Program - User Defined Function

import java.util.Scanner; class Tech{ public static void main(String args[]){ for(int i = 1000; i <= 9999; i++){ if(isTech(i)) System.out.print(i + "\t"); } } public static boolean isTech(int n){ int a = n / 100; int b = n % 100; int sum = a + b; if(n == sum * sum) return true; return false; } }

Output

 
 OUTPUT : 
2025 3025 9801