Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
class Point { private float x; private float y; public Point(float x, float y) { changeCoords(x, y); } public void changeCoords(float x, float y) { this.x = x; this.y = y; } @Override public String toString() { return "(" + x + ", " + y + ")"; } } class Polygon { private final Point[] points; public Polygon(int n) { points = new Point[n]; for (int i = 0; i < n; i++) { points[i] = new Point(0, 0); } } public Polygon(float[] coords) { if (coords.length % 2 != 0) { throw new IllegalArgumentException("len is odd"); } int n = coords.length / 2; this(n); for (int i = 0; i < n; i++) { points[i] = new Point(coords[2 * i], coords[2 * i + 1]); } } @Override public String toString() { StringBuilder sb = new StringBuilder("Polygon: "); for (Point p : points) { sb.append(p.toString()).append(" "); } return sb.toString(); } } public class Main { public static void main(String[] args) { Polygon poly1 = new Polygon(3); System.out.println(poly1); float[] coords = {0, 0, 1, 0, 1, 1, 0, 1}; Polygon poly2 = new Polygon(coords); System.out.println(poly2); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)