Tech Number 2

 Write a program to input a numbers and check it is tech number or not.

A tech number can be tech number if its digits are even and the number of digits split into two number from middle then add these number if the added number's square would be the same with the number it will called a Tech Number .

Example : Number : 2025

Number of digits must be even.

1. Divide number from middle (20,25)

2. 20 + 25 = 45

3. Square of (45) = 2025 = number

 

import java.util.*; class TechNumber { public static void main() { System.out.println("Enter any number \n"); Scanner in = new Scanner(System.in); int x = in.nextInt(); int i=0,temp; for(temp=x;temp!=0;i++) // count the number of digits temp/=10; if(i%2==0) { int a,b; a= x % (int)Math.pow(10,i/2);//first half b= x / (int)Math.pow(10,i/2);//second half if((a+b)*(a+b)==x) // comparing squares by number System.out.println(x+" is a tech number"); else System.out.println(x+" is not a tech number"); } else System.out.println(x+" can't be tech number as number of digits is odd"); } }


For any desired program, please comment below. We will try our best to make that program available.

Comments

Popular Posts