Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LiczbyZespolone.java - klasa liczb zespolonych */
- import java.util.*;
- import java.lang.String;
- class Zespolone {
- public static class LiczbyZespolone {
- private double re; // część rzeczywista
- private double im; // część urojona
- /* konstruktor */
- public LiczbyZespolone(Scanner input) {
- System.out.println("Podaj czesc rzeczywista: ");
- this.re = input.nextDouble();
- System.out.println("Podaj czesc urojona: ");
- this.im = input.nextDouble();
- }
- /* dodawanie */
- public static void add(LiczbyZespolone c1, LiczbyZespolone c2) {
- double repart = c1.re + c2.re;
- double impart = c1.im + c2.im;
- System.out.println("Suma liczb urojonych wynosi: " + +repart + " + " + impart + "i");
- }
- /* odejmowanie */
- public static void sub(LiczbyZespolone c1, LiczbyZespolone c2) {
- double repart = c1.re - c2.re;
- double impart = c1.im - c2.im;
- System.out.println("Roznica liczb urojonych wynosi: " + repart + " + " + impart + "i");
- }
- /* mnożenie */
- public static void multiply(LiczbyZespolone c1, LiczbyZespolone c2) {
- double repart = c1.re * c2.re - c1.im * c2.im;
- double impart = c1.re * c2.im + c1.im * c2.re;
- System.out.println("Iloczyn liczb urojonych wynosi: " + repart + " + " + impart + "i");
- }
- public static double module(LiczbyZespolone c) {
- return Math.sqrt(Math.pow(c.re, 2) + Math.pow(c.im, 2));
- }
- public static double realPart(LiczbyZespolone c) {
- return c.re;
- }
- public static double imPart(LiczbyZespolone c) {
- return c.im;
- }
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- LiczbyZespolone c = new LiczbyZespolone(input);
- System.out.println("Wartosc bezwzgledna liczb urojonych wynosi: " + LiczbyZespolone.module(c));
- System.out.println("Czesc rzeczywista liczby zespolonej wynosi: " + LiczbyZespolone.realPart(c));
- System.out.println("Czesc urojona liczby zespolonej wynosi: " + LiczbyZespolone.imPart(c));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement