Java面向物件6(AA ~ AE)
阿新 • • 發佈:2018-12-18
AE 簡單的複數運算(類和物件) (SDUT 4303)
import java.util.*; class Complex { int a, b; Complex() { } Complex(int n, int m) { a = n; b = m; } void getAns(int x, int y, int z) { if (z == 1) { a += x; b += y; } else if (z == 2) { a -= x; b -= y; } else if (z == 3) { int temp = a; a = a * x - b * y; b = temp * y + b * x; } } void Print() { System.out.println(a + " " + b); } } public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int x, y, z; Complex p = new Complex(sc.nextInt(), sc.nextInt()); while (sc.hasNext()) { x = sc.nextInt(); y = sc.nextInt(); z = sc.nextInt(); if (x == 0 && y == 0 && z == 0) { p.Print(); break; } else p.getAns(x, y, z); // p.Print(); } } }