Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. class Vector {
  5. float x,y;
  6.  
  7. Vector (float x, float y) {
  8. x = x;
  9. y = y;
  10. }
  11.  
  12. public static Vector Add (Vector v1, Vector v2) {
  13. float nx,ny;
  14. nx = v1.x + v2.x;
  15. ny = v1.y + v2.y;
  16. return new Vector(nx,ny);
  17. }
  18. public static Vector Sub (Vector v1, Vector v2) {
  19. float nx,ny;
  20. nx = v1.x - v2.x;
  21. ny = v1.y - v2.y;
  22. return new Vector(nx,ny);
  23. }
  24. public static Vector Mul (Vector v1, Vector v2) {
  25. float nx,ny;
  26. nx = v1.x * v2.x;
  27. ny = v1.y * v2.y;
  28. return new Vector(nx,ny);
  29. }
  30. public static Vector MulByNum (Vector v1, float n) {
  31. float nx,ny;
  32. nx = v1.x * n;
  33. ny = v1.y * n;
  34. return new Vector(nx,ny);
  35. }
  36. public static Vector Div (Vector v1, int n) {
  37. return Vector.MulByNum(v1,1/n);
  38. }
  39.  
  40. public static Vector Neg (Vector v1,) {
  41. float nx,ny;
  42. nx = - v1.x ;
  43. ny = - v1.y ;
  44. return new Vector(nx,ny);
  45. }
  46.  
  47. public static float Abs (Vector v1) {
  48. return Math.abs(v1.x) + Math.abs(v1.y);
  49. }
  50.  
  51. public static void print(Vector v) {
  52. System.out.println( "[" + v.x + ", " +v. y+"]");
  53. }
  54. }
  55.  
  56.  
  57. public class Main {
  58.  
  59. public static void main(String[] args) {
  60.  
  61. final int i = 2;
  62. Vector v1 = new Vector (i , 4);
  63. Vector v2 = new Vector (1 , 4);
  64. Vector v3 = Vector.Add(v1,v2);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement