JAVA- Tech Number Program.

Easy way to solve TECH NUMBER program.


 import java.util.Scanner;  

public class TechNumber
{  
public static void main(String args[])  
{  
int n, num, firstHalf, secondHalf, digits = 0, squareOfSum = 0;  
Scanner sc = new Scanner(System.in);  
System.out.print("Enter a number to check: ");
n = sc.nextInt();  
num = n;    
while (num > 0)  
{        
digits++;  
num = num / 10;  
}    
if (digits % 2 == 0)  
{  
num = n;  
firstHalf = num % (int) Math.pow(10, digits / 2);
secondHalf = num / (int) Math.pow(10, digits / 2);  
squareOfSum = (firstHalf + secondHalf) * (firstHalf + secondHalf);  
if (n == squareOfSum)  
{  
System.out.println(n+" is a tech number.");  
}  
else  
{  
System.out.println(n+" is not a tech number.");  
}  
}  
else  
{  
System.out.println(n+ " is not a tech number.");  
}  
}  
}  

Popular posts from this blog

Develop an object oriented program in C++ to create a database of student information system containing the following information: Name, Roll number, Class, division, Date of Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, Copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.

Calculate the Nth term - Hacker Rank Solution .

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float).Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members. If an exception is caught, replace all the data member values with zero values.