Advertisement
Guest User

Pszemek

a guest
Apr 8th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public class Zad29 {
  2.         public static double poleWielokata(double[][] wspolrzedne){
  3.             double pole = 0.0;
  4.             for(int x = 0; x < wspolrzedne.length-1; x++){
  5.                 for(int y = 0; y < wspolrzedne[x].length-1; y++){
  6.                     pole += ((wspolrzedne[x][y] * wspolrzedne[x+1][y+1]) - (wspolrzedne[x+1][y] * wspolrzedne[x][y+1]));
  7.                 }
  8.             }
  9.             pole += ((wspolrzedne[wspolrzedne.length-1][0] * wspolrzedne[0][1]) - (wspolrzedne[0][0] * wspolrzedne[wspolrzedne.length-1][1]));
  10.  
  11.             return Math.abs(pole/2);
  12.         }
  13.     public static void main(String[] args) {
  14.  
  15.         double[][] testowaTablica = {{1.0, 1.0}, {2.0, 6.0}, {5.0, 5.0}, {7.0, 0.0}};
  16.  
  17.         System.out.println(poleWielokata(testowaTablica));
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement