Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
41
Task/Vector/Java/vector.java
Normal file
41
Task/Vector/Java/vector.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import java.util.Locale;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Vec2(5, 7).add(new Vec2(2, 3)));
|
||||
System.out.println(new Vec2(5, 7).sub(new Vec2(2, 3)));
|
||||
System.out.println(new Vec2(5, 7).mult(11));
|
||||
System.out.println(new Vec2(5, 7).div(2));
|
||||
}
|
||||
}
|
||||
|
||||
class Vec2 {
|
||||
final double x, y;
|
||||
|
||||
Vec2(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
Vec2 add(Vec2 v) {
|
||||
return new Vec2(x + v.x, y + v.y);
|
||||
}
|
||||
|
||||
Vec2 sub(Vec2 v) {
|
||||
return new Vec2(x - v.x, y - v.y);
|
||||
}
|
||||
|
||||
Vec2 div(double val) {
|
||||
return new Vec2(x / val, y / val);
|
||||
}
|
||||
|
||||
Vec2 mult(double val) {
|
||||
return new Vec2(x * val, y * val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.US, "[%s, %s]", x, y);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue