Google News
logo
Java program to Tech Number
A Tech number is a number whose digits are even and the number itself is divisible by the count of even digits in the number.

For example, 246 is a Tech number as it has three even digits and is divisible by three.

Here is the Java program to check whether a given number is a Tech number or not :
Program :
import java.util.Scanner;

public class TechNumber {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();
        int count = 0, temp = num;
        while (temp > 0) {
            int digit = temp % 10;
            if (digit % 2 == 0) {
                count++;
            }
            temp /= 10;
        }
        if (num % count == 0) {
            System.out.println(num + " is a Tech number.");
        } else {
            System.out.println(num + " is not a Tech number.");
        }
        sc.close();
    }
}
Output :
Enter a number: 246
246 is a Tech number.
Enter a number: 280
280 is not a Tech number.
In this program, we first take a number as input from the user using the Scanner class. We then count the number of even digits in the number by dividing the number by 10 repeatedly and checking the remainder of each division. We use a while loop for this.

After counting the even digits, we check whether the number is divisible by the count of even digits using an if-else statement. If it is divisible, we print that the number is a Tech number, otherwise we print that it is not a Tech number.