[JAVA-PRACTICE] - Giải Hệ Phương Trình Bậc Nhất (có Khả Năng Thi ...

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@LaBanHSPO LaBanHSPO/HePtB1.java Last active December 7, 2015 12:03 Show Gist options
  • Star (0) You must be signed in to star a gist
  • Fork (0) You must be signed in to fork a gist
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/LaBanHSPO/faad67805276185a902e.js"></script>
  • Save LaBanHSPO/faad67805276185a902e to your computer and use it in GitHub Desktop.
Code Revisions 9 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/LaBanHSPO/faad67805276185a902e.js"></script> Save LaBanHSPO/faad67805276185a902e to your computer and use it in GitHub Desktop. Download ZIP [JAVA-PRACTICE] - Giải hệ phương trình bậc nhất (có khả năng thi kết thúc học phần >viết code + vấn đáp) Raw HePtB1.java This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
package ktpmk12b-ictu;
import java.util.Scanner;
/**
*
* @author HARD-Code
*/
public class HePtB1 {
double a1, b1, c1;
double a2, b2, c2;
public void Input() {
Scanner s = new Scanner(System.in);
System.out.println("------------SSG-----------");
System.out.println("Vao he so: a1, b1, c1 = ");
a1 = s.nextDouble(); b1 = s.nextDouble(); c1 = s.nextDouble();
System.out.println("--Het PT1. Moi ban Nhap PT2--");
System.out.println("a2, b2, c2 = ");
a2 = s.nextDouble(); b2 = s.nextDouble(); c2 = s.nextDouble();
System.out.println("-------Hoan thanh Nhap-------");
System.out.println("");
}
public void PpThe(){
double b11=b1*a2;
double c11=c1*a2;
double b22=b2*a1;
double c22=c2*a1;
double y = (c22-c11)/(b11-b22);
System.out.println("y = "+y);
double x = (-c11-b11*y)/(a1*a2);
System.out.println("x = "+x);
}
}
Raw Main.java This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
package ktpmk12b-ictu;
/**
* @author HARD-Code
*/
public class Main {
public static void main(String[] args) {
HePtB1 pt1 = new HePtB1();
pt1.Input();
if (!THUATTOAN.checkPTVN(pt1)) {
System.out.println("__TB: PT VÔ NGHIÊM__");
} else {
System.out.println("-----NGHIEM THEO PP THẾ-------");
pt1.PpThe();
Double D[] = THUATTOAN.DinhThuc(pt1);
System.out.println("----NGHIEM THEO ĐỊNH THỨC-----");
System.out.println("Phuong trinh co nghiem la:");
System.out.println("y= " + D[2] / D[0]);
System.out.println("x= " + D[1] / D[0]);
}
}
}
Raw THUATTOAN.java This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
package ktpmk12b-ictu;
/**
*
* @author HARD-Code
*/
public class THUATTOAN {
/**
* @param pt:(ax+b+c=0) => pt.a1 pt.b1 -pt.c1
* Return: D[0] = D a1b2 - a2b1
* D[1]= Dx c1.b2 - b1.c2
* D[2]= Dy a1.c2 - c1. a2
*/
public static Double[] DinhThuc(HePtB1 pt) {
Double D[] = new Double[3];
D[0] = (pt.a1 * pt.b2) - (pt.a2 * pt.b1);
D[1] = ((-(pt.c1)) * pt.b2) - (pt.b1 * (-(pt.c2)));
D[2] = (pt.a1 * (-(pt.c2))) - (pt.a2 * (-(pt.c1)));
return D;
}
public static boolean checkPTVN(HePtB1 _pt) {
boolean check = true;
if (((_pt.a1 / _pt.a2) == (_pt.b1 / _pt.b2)) && ((_pt.c1 / _pt.c2) == (_pt.b1 / _pt.b2)))
check = false;
if ((_pt.a1 ==0 && _pt.a2==0 ) || (_pt.a2 ==0 && _pt.b2 ==0)) check =false;
double c = THUATTOAN.DinhThuc(_pt)[0];
if (c==0) check=false;
return check;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Từ khóa » Giải Hệ Phương Trình Bậc Nhất 2 ẩn Bằng Java