Advertisement
GabrieleLoprieno

ProvaComplesso

Nov 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.61 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class ProvaComplesso {
  4.  
  5.     public static void main(String[] args) {
  6.         Random randomizer = new Random();
  7.         Complesso [] c = new Complesso[5];
  8.         for(int i=0; i<5; i++){
  9.             c[i]=new Complesso(randomizer.nextDouble(), randomizer.nextDouble());
  10.             System.out.println("Complesso n." + (i+1) + " : " + c[i].getA() + " (reale) " + c[i].getB() + "(immaginaria)");
  11.         }
  12.         Complesso sum = c[0];
  13.         for(int i=1; i<5; i++){
  14.             sum = sum.sum(c[i]);
  15.         }
  16.         System.out.println("La somma dei numeri complessi e' : " + sum.getA() + "(parte reale) " + sum.getB() + "(parte immaginaria)");
  17.     }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement