Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex {
- private static long cnt = 0;
- private double re, img;
- public Complex(double re, double img) {
- this.re = re;
- this.img = img;
- }
- public double abs() {
- return Math.sqrt(re * re + img * img);
- }
- public void print() {
- System.out.println(re + " + " + img + "i");
- Complex.cnt++;
- }
- public Complex add(final Complex other) {
- return new Complex(re + other.re, img + other.img);
- }
- public static long getCnt() {
- return Complex.cnt;
- }
- }
- class ClientComplex {
- public static void main(String argv[]) {
- Complex a = new Complex(3, -2);
- Complex b = new Complex(3, 4);
- a.print();
- a.add(b).print();
- System.out.println(b.abs());
- System.out.println(Complex.getCnt());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement