Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Locale;
- public class SecondDegreeEquationv2 {
- static void sde(int a, int b, int c) {
- if (a==0) {
- if (b==0) {
- if (c==0) {
- System.out.println("infinite solutions");
- }
- else {
- System.out.println("undetermined");
- }
- }
- else {
- double x = (-c*1.0)/(b);
- System.out.printf("%d %d %d %.4f first degree equation\n", a, b, c, x);
- }
- }
- else {
- if (b*b >= 4*a*c) {
- if (b*b == 4*a*c) {
- double x = (-b)/(2.0*a);
- System.out.printf("%.4f double solution\n", x);
- }
- else {
- double x1 = (-b+Math.sqrt(b*b-4.0*a*c))/(2.0*a);
- double x2 = (-b-Math.sqrt(b*b-4.0*a*c))/(2.0*a);
- System.out.printf("%.4f and %.4f\n", x1, x2);
- }
- }
- else {
- double real = (-b)/(2.0*a);
- double im = Math.abs(Math.sqrt(4.0*a*c-b*b)/(2.0*a));
- System.out.printf("%.4f + %.4fi and %.4f - %.4fi\n", real, im, real, im);
- }
- }
- }
- public static void main(String[] args) {
- Scanner kbd = new Scanner( System.in ).useLocale( Locale.US );
- while (kbd.hasNext()) {
- int a = kbd.nextInt();
- int b = kbd.nextInt();
- int c = kbd.nextInt();
- sde(a, b, c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement