daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Jun 5th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type numbers struct {
  6.     X int
  7.     Y int
  8. }
  9.  
  10. func (n numbers) addTimes() int {
  11.     return n.X*n.X + n.Y*n.Y
  12. }
  13.  
  14. func (n *numbers) Scale(i int) { // if missing * it will not change n.X and n.Y
  15.     n.X = n.X * i
  16.     n.Y = n.Y * i
  17. }
  18.  
  19. func main() {
  20.     n := numbers{X: 2, Y: 3}
  21.     fmt.Println(n.addTimes())
  22.     n.Scale(2)
  23.     fmt.Println(n.addTimes())
  24. }
  25.  
  26. /*
  27. 13
  28. 52
  29. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top