FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Others/RootPrecision.java at dev · primary-code-test/Java · GitHub
primary-code-test
Java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Others
/
RootPrecision.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (26 loc) · 877 Bytes
Breadcrumbs
Java
/
Others
/
RootPrecision.java
Copy path
File metadata and controls
36 lines (26 loc) · 877 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
Others
;
import
java
.
util
.
Scanner
;
public
class
RootPrecision
{
public
static
void
main
(
String
[]
args
) {
// take input
Scanner
scn
=
new
Scanner
(
System
.
in
);
// N is the input number
int
N
=
scn
.
nextInt
();
// P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
int
P
=
scn
.
nextInt
();
System
.
out
.
println
(
squareRoot
(
N
,
P
));
scn
.
close
();
}
public
static
double
squareRoot
(
int
N
,
int
P
) {
// rv means return value
double
rv
;
double
root
=
Math
.
pow
(
N
,
0.5
);
// calculate precision to power of 10 and then multiply it with root value.
int
precision
= (
int
)
Math
.
pow
(
10
,
P
);
root
=
root
*
precision
;
/*typecast it into integer then divide by precision and again typecast into double
so as to have decimal points upto P precision */
rv
= (
int
)
root
;
return
rv
/
precision
;
}
}
Back
|
FazBrowse Home
|
New Git URL