我想写个模块 功能很简单 比如 写一个 求三角形面积的模块?怎么写 我会写vb的 那Java的话 是不是还要 set get?谁帮我写下吧Module Shape Public Function tectangle(ByVal b As Double, ByVal h As Double) As Double '三角形
Dim s As Double = b * h * 0.5
Return s
End FunctionEnd Module
Dim s As Double = b * h * 0.5
Return s
End FunctionEnd Module
return b*h*0.5;
}
static double computer(double x, double y){
return (x*y)/2;
}
public static double Tectangle(double b, double h) {
return b*h*0.5;
}
}不好意思没看清LZ要求是模块,在java里面大概用静态方法可以解决你的问题吧,使用的时候直接用
Helper.Tectangle()就可以了
Module Shape
Public Function tectangle(ByVal b As Double, ByVal h As Double) As Double '三角形
Dim s As Double = b * h * 0.5
Return s
End Function
End Module 那Java的是
public class Module Shape{
public double Tectangle(double b, double h) {
return b*h*0/2;
}
}就这样?这样就可以调用了?
public static double tectangle(double height,double bottom) {
return height * bottom * 0.5;
}
public static double Tectangle(double b, double h) {
return (b*h)/2;
}
}
调用的时候
ModuleShape.Tectangle(3,5);
public static void main(String args[]){
double bottom = 3d;
double height = 4d;
System.out.println("The area is : " + area(bottom,height));
}
public static double area(double bottom,double height){
return bottom * height / 2;
}
}
public class Shape 就可以了,java没有module关键字的
Java codepublic class ModuleShape{
public static double Tectangle(double b, double h) {
return (b*h)/2;
}
}调用的时候
ModuleShape.Tectangle(3,5);
{
double a;
couble b;
public tectangle(double a,double b)
{
return (a*b)/2;
}
public static void main(String args[])
{
tectangle t = new tectangle(number1,number2);
System.out.println(t.tectangle());
}
}
return (b*h)/2;
}为什么楼上的都要加 static 呢?
lz好像没有要求吧!