forked from dscmsit/Problem-Solving-in-any-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTechNumber.java
More file actions
46 lines (36 loc) · 837 Bytes
/
TechNumber.java
File metadata and controls
46 lines (36 loc) · 837 Bytes
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
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.");
}
}
}