标签:pack wav 常用 -- imp odm package sae fun
public class Test {
static class Vertex{
public double x;
public double y;
}
static double abs(Vertex v) {
return Math.sqrt(v.x * v.x + v.y * v.y);
}
static void scale(Vertex v, double f) {
v.x = v.x * f;
v.y = v.y * f;
}
public static void main(String[] args) {
Vertex vertex = new Vertex();
vertex.x = 3;
vertex.y = 4;
System.out.println(abs(vertex)); // 5
scale(vertex, 10);
System.out.println(abs(vertex)); // 50
}
}
package main
import (
"fmt"
"math"
)
type Vertex struct {
X, Y float64
}
func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func (v *Vertex) Scale(f float64) {
v.X = v.X * f
v.Y = v.Y * f
}
func main() {
v := Vertex{3, 4}
v.Scale(10)
fmt.Println(v.Abs()) // 50
}
标签:pack wav 常用 -- imp odm package sae fun
原文地址:https://www.cnblogs.com/sxpujs/p/11941166.html