Complex.java - Gists · GitHub
Có thể bạn quan tâm
Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }}
xuanthulabnet/Complex.java Created September 11, 2019 16:20 Show Gist options
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.
Instantly share code, notes, and snippets.
- Download ZIP
- 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/xuanthulabnet/a899e15113174be7c6fdb5bf8af48e93.js"></script> - Save xuanthulabnet/a899e15113174be7c6fdb5bf8af48e93 to your computer and use it in GitHub Desktop.
- 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/xuanthulabnet/a899e15113174be7c6fdb5bf8af48e93.js"></script> Save xuanthulabnet/a899e15113174be7c6fdb5bf8af48e93 to your computer and use it in GitHub Desktop. Download ZIP Raw Complex.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 net.xuanthulab; |
| public class Complex { |
| private double re; // phần thực |
| private double im; // phần ảo |
| //Thiết lập phần thực vào ảo |
| private void Init(double re, double im) { |
| this.re = re; |
| this.im = im; |
| }; |
| // Khởi tạo mặc định, không tham số (phần ảo, thực bằng 0) |
| public Complex() { |
| Init(0,0); |
| } |
| // Khởi tạo với phần thực và phần ảo |
| public Complex(double re, double im) { |
| Init(re, im); |
| } |
| // Khởi tạo 1 tham số là phần thực, phần ảo bằng 0 |
| public Complex(double re) { |
| Init(re, 0); |
| } |
| // Khởi tạo từ một số phức khác |
| public Complex(Complex complex) { |
| Init(complex.getRe(), complex.getIm()); |
| } |
| //Getter thuộc tinh phần thực re |
| public double getRe() { |
| return re; |
| } |
| public double getIm() { |
| return im; |
| } |
| //Setter thuộc tinh phần thực re |
| public void setRe(double re) { |
| this.re = re; |
| } |
| public void setIm(double im) { |
| this.im = im; |
| } |
| // phép cộng hai số phức a + b |
| public static Complex cong(Complex a, Complex b) { |
| double real = a.re + b.re; |
| double imag = a.im + b.im; |
| return new Complex(real, imag); |
| } |
| // Trừ 2 số phức a - b |
| public static Complex tru(Complex a, Complex b) { |
| double real = a.re - b.re; |
| double imag = a.im - b.im; |
| return new Complex(real, imag); |
| } |
| // Nhân 2 số phức a * b |
| public static Complex nhan(Complex a,Complex b) { |
| double real = a.re * b.re - a.im * b.im; |
| double imag = a.re * b.im + a.im * b.re; |
| return new Complex(real, imag); |
| } |
| // Chia 2 số phức a / b |
| public static Complex chia(Complex a, Complex b) { |
| double _re = b.getRe(); |
| double _im = b.getIm(); |
| double scale = _re*_re + _im*_im; |
| return nhan(a, new Complex(_re / scale, -_im / scale)); |
| } |
| public String toString() { |
| if (im == 0) return re + ""; |
| if (re == 0) return im + "i"; |
| if (im < 0) return re + " - " + (-im) + "i"; |
| return re + " + " + im + "i"; |
| } |
| } |
Từ khóa » Tính Số Phức Trong Java
-
Tạo Và Sử Dụng Lớp Số Phức Trong Java | Tìm ở đây
-
Cộng Hai Số Phức Trong Java - Freetuts
-
Cộng Hai Số Phức Trong Java - Bài Tập Java Có Lời Giải Cơ Bản đến ...
-
Bài Tập Java Số 19: Tính Tổng, Hiệu Và Tích Của 2 Số Phức
-
Chương Trình Java để Thêm Hai Số Phức - Đi Mã Hóa - Go Coding
-
Bài 25 Bài Tập Java Số Phức
-
Cộng Hai Số Phức Trong Java - Freetuts - Trang Giới Thiệu Tốp Hàng ...
-
Bài Tập Lập Trình - Programming - Dạy Nhau Học
-
Giải Phương Trình Bậc 2 Trong Java - Bài Tập Java Có Lời Giải - Viettuts
-
Bài Tập Lập Trình Java Cơ Bản Có Lời Giải - Tài Liệu Text - 123doc
-
Diễn Giải Chi Tiết Về OOP Trong Java - Viblo
-
[Selenium Java] Bài 2: Java OOP Hướng đối Tượng | Anh Tester
-
(DOC) Growth And Convergence In A Model With Renewable And ...