FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Crash-Course/Task/Task1.java at master · sundramsinghdev007/Java-Crash-Course · GitHub
sundramsinghdev007
/
Java-Crash-Course
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Crash-Course
/
Task
/
Task1.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (42 loc) · 1.48 KB
Breadcrumbs
Java-Crash-Course
/
Task
/
Task1.java
Copy path
File metadata and controls
43 lines (42 loc) · 1.48 KB
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
37
38
39
40
41
42
43
//Develop a program in java which calculate roots of quadratic equation ax2+bx+c=0. Use Math.sqrt() function to calculate square root.
import
java
.
util
.*;
class
root
{
public
static
void
main
(
String
...
args
)
{
double
a
,
b
,
c
,
D
,
root1
,
root2
,
real
,
imaginary
;
Scanner
s
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter the coefficient of x*x of equation:"
);
a
=
s
.
nextInt
();
System
.
out
.
print
(
"Enter the coefficient of y of equation:"
);
b
=
s
.
nextInt
();
System
.
out
.
print
(
"Enter the indenpendent term of equation:"
);
c
=
s
.
nextInt
();
D
=
b
*
b
-
4
*
a
*
c
;
//discriminat.
System
.
out
.
println
(
"Discriminat. of equation:"
+
D
);
if
(
D
==
0
)
{
root1
=(-
b
+
Math
.
sqrt
(
D
))/(
2
*
a
);
System
.
out
.
println
(
"Roots are real and equal:"
+
"("
+
root1
+
","
+
root1
+
")"
);
}
else
if
(
D
>
0
)
{
root1
=(-
b
+
Math
.
sqrt
(
D
))/(
2
*
a
);
root2
=(-
b
-
Math
.
sqrt
(
D
))/(
2
*
a
);
System
.
out
.
println
(
"Roots are real and equal:"
+
"("
+
root1
+
","
+
root2
+
")"
);
}
//when D<0 roots are imaginary
else
{
real
=-
b
/(
2
*
a
);
imaginary
=
Math
.
sqrt
(
D
)/(
2
*
a
);
System
.
out
.
println
(
"Roots are imaginary:"
+
"("
+
real
+
","
+
imaginary
+
")"
);
}
}
}
/*
The quantity b2 - 4ac inside the radical is called discriminat.
• If b2 - 4ac = 0, the roots are real and equal.
• If b2 - 4ac > 0, the roots are real and unequal.
• If b2 - 4ac < 0, the roots are imaginary.
*/
Back
|
FazBrowse Home
|
New Git URL