-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPT1.java
29 lines (26 loc) · 1.17 KB
/
PT1.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
package buoi1;
import java.text.DecimalFormat;
import java.util.Scanner;
public class PT1 {
public static void main(String[] args) {
int aNumber, bNumber;
double nghiem;
DecimalFormat decimalFormat = new DecimalFormat("#.##"); // làm tròn đến 2 chữ số thập phân
Scanner scanner = new Scanner(System.in);
System.out.println("Nhập vào số a: ");
aNumber = scanner.nextInt();
System.out.println("Nhập vào số b: ");
bNumber = scanner.nextInt();
System.out.println("Phương trình bạn vừa nhập vào là: " + aNumber + "x + " + bNumber + " = 0.");
if (aNumber == 0) {
if (bNumber == 0) {
System.out.println("Phương trình này có vô số nghiệm.");
} else {
System.out.println("Phương trình vô nghiệm.");
}
} else {
nghiem = (double) -bNumber / aNumber; // ép kiểu để cho ra kết quả chính xác
System.out.println("Phương trình có nghiệm x = " + decimalFormat.format(nghiem) + ".");
}
}
}