+ 1
How to check for a tech number in java?
Example 3025 = (30 + 25)²=(55)²=3025
4 ответов
0
My attempt:
import java.io.*;
import java.util.*;
class Tech_Number
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,l,a,b,sum,sq,div;
String str,str1,str2;
System.out.println("Enter Number");
str= in.nextLine();//input number as a string
l=str.length();//calculating length of string
n= Integer.parseInt(str);//converting input number as integer
if(l%2==0)
{
div= l/2;
str1= str.substring(0,div);//storing 1st half as string
str2= str.substring(div,l);//storing 2nd half as string
a= Integer.parseInt(str1);//converting 1st half into integer
b= Integer.parseInt(str2);//converting 2nd half into integer
sum= a+b; //sum of the two halves
sq= sum*sum; // square of sum of two halves
if(n==sq)
{
System.out.println("It is a Tech Number : "+n);
}
else
0
Your attempt??
0
You marked your answer as best does that mean you solved it
0
Yes