Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- public class PGRF2_test1 {
- public static class Point2D {
- public double x, y, w;
- public Point2D() {
- x = y = 0.0;
- w = 1.0;
- }
- public Point2D(Point2D v) {
- x = v.x;
- y = v.y;
- w = v.w;
- }
- public Point2D(double x, double y) {
- this.x = x;
- this.y = y;
- w = 1.0;
- }
- }
- public static Point2D[][] pole = new Point2D[10][10];
- static DecimalFormat df = new DecimalFormat("#.###");
- // formatovani informacniho vypisu
- private static void otazka2() {
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- pole[i][j] = new Point2D(Math.random(), Math.random());
- /* informacni vypis */
- System.out.println("pole[" + i + "][" + j + "]: x = "
- + df.format(pole[i][j].x) + " y = "
- + df.format(pole[i][j].y));
- /* informacni vypis */
- }
- }
- }
- private static void otazka3() {
- Point2D max = pole[0][0];
- // zatim nezname maximum, takze je prvni prvek pro nas nejevetsi znamy
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- if (max.x < pole[i][j].x) {
- max = pole[i][j];
- }
- }
- }
- /* informacni vypis */
- System.out.println("maximum: x = " + df.format(max.x) + " y = "
- + df.format(max.y));
- /* informacni vypis */
- }
- private static void otazka4() {
- Point2D a = new Point2D();
- Point2D b = new Point2D(a);
- Point2D c = new Point2D(-5, 0);
- a = c;
- a.x += 10;
- b.x += 2;
- if (c.x > b.x) {
- a.x++;
- }
- a.y = 3;
- b.y += a.y++;
- System.out.println("a.x = " + a.x);
- System.out.println("a.y = " + a.y);
- System.out.println("b.x = " + b.x);
- System.out.println("b.y = " + b.y);
- System.out.println("c.x = " + c.x);
- System.out.println("c.y = " + c.y);
- }
- public static void main(String[] args) {
- System.out.println("Otazka 2:");
- otazka2();
- System.out.println("\n Otazka 3:");
- otazka3();
- System.out.println("\n Otazka 4:");
- otazka4();
- }
- }
- /*
- VYSTUP:
- Otazka 2:
- pole[0][0]: x = 0,312 y = 0,686
- pole[0][1]: x = 0,659 y = 0,882
- pole[0][2]: x = 0,568 y = 0,163
- pole[0][3]: x = 0,899 y = 0,362
- pole[0][4]: x = 0,042 y = 0,835
- pole[0][5]: x = 0,778 y = 0,306
- pole[0][6]: x = 0,193 y = 0,885
- pole[0][7]: x = 0,618 y = 0,225
- pole[0][8]: x = 0,979 y = 0,591
- pole[0][9]: x = 0,183 y = 0,101
- pole[1][0]: x = 0,615 y = 0,274
- pole[1][1]: x = 0,789 y = 0,716
- pole[1][2]: x = 0,552 y = 0,581
- pole[1][3]: x = 0,194 y = 0,104
- pole[1][4]: x = 0,564 y = 0,804
- pole[1][5]: x = 0,058 y = 0,913
- pole[1][6]: x = 0,655 y = 0,606
- pole[1][7]: x = 0,186 y = 0,807
- pole[1][8]: x = 0,69 y = 0,882
- pole[1][9]: x = 0,019 y = 0,633
- pole[2][0]: x = 0,279 y = 0,454
- pole[2][1]: x = 0,046 y = 0,729
- pole[2][2]: x = 0,443 y = 0,002
- pole[2][3]: x = 0,912 y = 0,649
- pole[2][4]: x = 0,056 y = 0,874
- pole[2][5]: x = 0,989 y = 0,551
- pole[2][6]: x = 0,848 y = 0,451
- pole[2][7]: x = 0,096 y = 0,714
- pole[2][8]: x = 0,013 y = 0,316
- pole[2][9]: x = 0,871 y = 0,912
- pole[3][0]: x = 0,125 y = 0,783
- pole[3][1]: x = 0,025 y = 0,92
- pole[3][2]: x = 0,083 y = 0,256
- pole[3][3]: x = 0,327 y = 0,011
- pole[3][4]: x = 0,298 y = 0,512
- pole[3][5]: x = 0,717 y = 0,137
- pole[3][6]: x = 0,178 y = 0,191
- pole[3][7]: x = 0,379 y = 0,403
- pole[3][8]: x = 0,242 y = 0,75
- pole[3][9]: x = 0,957 y = 0,582
- pole[4][0]: x = 0,877 y = 0,639
- pole[4][1]: x = 0,355 y = 0,649
- pole[4][2]: x = 0,832 y = 0,711
- pole[4][3]: x = 0,716 y = 0,764
- pole[4][4]: x = 0,022 y = 0,721
- pole[4][5]: x = 0,247 y = 0,688
- pole[4][6]: x = 0,129 y = 0,328
- pole[4][7]: x = 0,533 y = 0,337
- pole[4][8]: x = 0,777 y = 0,164
- pole[4][9]: x = 0,858 y = 0,11
- pole[5][0]: x = 0,763 y = 0,412
- pole[5][1]: x = 0,838 y = 0,621
- pole[5][2]: x = 0,955 y = 0,798
- pole[5][3]: x = 0,367 y = 0,692
- pole[5][4]: x = 0,964 y = 0,074
- pole[5][5]: x = 0,468 y = 0,825
- pole[5][6]: x = 0,658 y = 0,886
- pole[5][7]: x = 0,161 y = 0,862
- pole[5][8]: x = 0,885 y = 0,357
- pole[5][9]: x = 0,847 y = 0,227
- pole[6][0]: x = 0,53 y = 0,871
- pole[6][1]: x = 0,053 y = 0,977
- pole[6][2]: x = 0,176 y = 0,299
- pole[6][3]: x = 0,583 y = 0,834
- pole[6][4]: x = 0,181 y = 0,358
- pole[6][5]: x = 0,256 y = 0,564
- pole[6][6]: x = 0,955 y = 0,867
- pole[6][7]: x = 0,465 y = 0,3
- pole[6][8]: x = 0,571 y = 0,432
- pole[6][9]: x = 0,707 y = 0,916
- pole[7][0]: x = 0,624 y = 0,483
- pole[7][1]: x = 0,095 y = 0,113
- pole[7][2]: x = 0,423 y = 0,635
- pole[7][3]: x = 0,63 y = 0,684
- pole[7][4]: x = 0,193 y = 0,097
- pole[7][5]: x = 0,647 y = 0,317
- pole[7][6]: x = 0,941 y = 0,175
- pole[7][7]: x = 0,433 y = 0,37
- pole[7][8]: x = 0,042 y = 0,997
- pole[7][9]: x = 0,493 y = 0,308
- pole[8][0]: x = 0,409 y = 0,217
- pole[8][1]: x = 0,302 y = 0,85
- pole[8][2]: x = 0,3 y = 0,846
- pole[8][3]: x = 0,68 y = 0,441
- pole[8][4]: x = 0,455 y = 0,327
- pole[8][5]: x = 0,122 y = 0,341
- pole[8][6]: x = 0,257 y = 0,619
- pole[8][7]: x = 0,498 y = 0,507
- pole[8][8]: x = 0,036 y = 0,4
- pole[8][9]: x = 0,566 y = 0,436
- pole[9][0]: x = 0,498 y = 0,416
- pole[9][1]: x = 0,626 y = 0,311
- pole[9][2]: x = 0,446 y = 0,663
- pole[9][3]: x = 0,483 y = 0,119
- pole[9][4]: x = 0,673 y = 0,357
- pole[9][5]: x = 0,599 y = 0,899
- pole[9][6]: x = 0,895 y = 0,57
- pole[9][7]: x = 0,94 y = 0,893
- pole[9][8]: x = 0,088 y = 0,012
- pole[9][9]: x = 0,58 y = 0,193
- Otazka 3:
- maximum: x = 0,989 y = 0,551
- Otazka 4:
- a.x = 6.0
- a.y = 4.0
- b.x = 2.0
- b.y = 3.0
- c.x = 6.0
- c.y = 4.0
- */
Advertisement
Add Comment
Please, Sign In to add comment