Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.Locale;
  2.  
  3. class Vector2D{
  4. double vx, vy;
  5. public Vector2D(){
  6. vx = 1;
  7. vy = 1;
  8. }
  9. public Vector2D(double vx, double vy){
  10. this.vx = vx;
  11. this.vy = vy;
  12. }
  13. public Vector2D(Vector2D v){
  14. this(v.vx, v.vy);
  15. }
  16.  
  17. @Override
  18. public String toString() {
  19. return "("
  20. + vx + ", " + vy +
  21. ")" ;
  22. }
  23. }
  24.  
  25. public class Main {
  26. public static void main(String[] args) {
  27. Vector2D v = new Vector2D(1.2374, 2.2334);
  28. Vector2D v2 = new Vector2D();
  29. Vector2D v3 = new Vector2D(v);
  30. System.out.println(String.format(Locale.US, "%.2f", v));
  31. System.out.println(String.format(Locale.US, "%.2f", v2));
  32. System.out.println(String.format(Locale.US, "%.2f", v3));
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement