Skip to content

Instantly share code, notes, and snippets.

@sangpt
Created November 10, 2016 06:59
Show Gist options
  • Save sangpt/25d34627f217ef736b4d36bc4b9d4628 to your computer and use it in GitHub Desktop.
Save sangpt/25d34627f217ef736b4d36bc4b9d4628 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package btvn1;
import java.util.Scanner;
/**
*
* @author Kawaii
*/
public class PTBac2 {
public static void main(String[] args) {
float a, b, c;
Scanner sc = new Scanner(System.in);
System.out.print("Nhap a: ");
a = sc.nextInt();
System.out.print("Nhap b: ");
b = sc.nextInt();
System.out.print("Nhap c: ");
c = sc.nextInt();
if (a == 0) {
if (b == 0 && c == 0) {
System.out.println("PT co vo so nghiem");
} else if (b == 0 && c != 0) {
System.out.println("PT vo nghiem");
} else {
System.out.println("PT co 1 nghiem duy nhat: x = " + -c / b);
}
} else {
float delta = b * b - 4 * a * c;
if (delta == 0) {
System.out.println("PT co nghiem kep x1 = x2 = " + -b / 2 * a);
} else if (delta < 0) {
System.out.println("PT vo nghiem");
} else {
System.out.println("PT co 2 nghiem x1 = " + (b + Math.sqrt(delta)) / (2 * a) + " va x2 = " + (-b + Math.sqrt(delta)) / (2 * a));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment