Advertisement
Josif_tepe

Untitled

Jun 17th, 2025
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. class Tocka {
  4.     private double x;
  5.     private double y;
  6.  
  7.  
  8.     public Tocka(double x, double y) {
  9.         this.x = x;
  10.         this.y = y;
  11.     }
  12.  
  13.     public double getX() {
  14.         return x;
  15.     }
  16.     public double getY() {
  17.         return y;
  18.     }
  19.     public void setX(double x) {
  20.         this.x = x;
  21.     }
  22.     public void setY(double y) {
  23.         this.y = y;
  24.     }
  25.  
  26. }
  27. public class Naloga14 {
  28.     static Tocka sredina(Tocka a, Tocka b) {
  29.         return new Tocka(0.5 * (a.getX() + b.getX()), 0.5 * (a.getY() + b.getY()));
  30.     }
  31.     public static void main(String[] args) {
  32.         StdDraw.setScale(0, 100);
  33.          Tocka[] tocki = new Tocka[3];
  34.          tocki[0] = new Tocka(10, 10);
  35.          tocki[1] = new Tocka(90, 10);
  36.          tocki[2] = new Tocka(50, 90);
  37.  
  38.          Random random = new Random();
  39.  
  40.          int x = random.nextInt(100);
  41.          int y;
  42.          if(x < 50) {
  43.             y = 2 * x + 1;
  44.          }
  45.          else {
  46.             y = 2 * (100 - x)+ 1;
  47.          }
  48.          Tocka tocka = new Tocka(x, y);
  49.  
  50.          for(int i = 0; i < 10000; i++) {
  51.             int j = random.nextInt(3);
  52.             Tocka sredisnaTocka = sredina(tocki[j], tocka);
  53.  
  54.             StdDraw.line(sredisnaTocka.getX(), sredisnaTocka.getY(), sredisnaTocka.getX(), sredisnaTocka.getY());
  55.             tocka = sredisnaTocka;
  56.          }
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement