-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsquare.java
87 lines (66 loc) · 2.09 KB
/
square.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class square
{
void disp(double n,int decimal)
{
String g=""+n;
int te=Integer.parseInt(g.substring(0,g.indexOf('.')));
String q=""+te;
if(te%2!=0)
q=""+0+te;
te=Integer.parseInt(q);
int count=0,point=0,extra=0,num=1,side=0,i;boolean check=true;
String a[]=new String[g.length()+decimal+2];
String ha=g.substring(g.indexOf('.')+1,g.length());
if(ha.length()%2!=0)
g=g+0;
if(Integer.parseInt(g.substring(g.indexOf('.')+1,g.length()))==0)
{
check=false;
extra=0;
}
while(num<=decimal+2)
{
for(i=0;i<=te+1;i++)
{
if(((side*10)+i)*i>te)
{
i=i-1;
a[count]=""+(i);
count++;
if(num==1&&decimal!=0)
{ a[count]=".";count++;point=g.indexOf('.');}
break ;
}
}
if(point>=g.length()-1&&check)
{
extra=0;check=false;
}
else if(check)
{
extra=Integer.parseInt(g.substring(point+1,point+3));
}
te=(te-((side*10)+i)*i)*100+extra;
side=(side*10+i);
if(num>1)
side=side+side%10;
else
side=2*side;
num++;
point=point+2;
}
for(int j=0;j<=count-2;j++)
{
if(j!=count-2)
System.out.print(a[j]);
else if(Integer.parseInt(a[j+1])>=5)
{
System.out.print(Integer.parseInt(a[j])+1);
}
else
{
System.out.print(a[j]);
}
}
}
}