JAVA求解

来源:百度知道 编辑:UC知道 时间:2024/06/28 00:07:24
调用一个来解决比较大小的包
例如:
math.max()
引用的格式是怎么样的?然后需要注意哪些

在API中,比较大小可以用java.lang.Max包,
用import导入,
而java.lang包是JVM默认导入的,
在程序开始,就不需要导入了,
然后在MAX的包中用max方法,
里面有好几个,
根据比较的数的类型,
调用就可以了,
写成
import java.lang.*;
public class Test{
public static void main(String args[]){
int a = 5;
int b = 7;
int c = 0;
c = Math.max(a,b);
System.out.println(c);
}
}

在看API时,static int max(int a, int b)
其为静态类型时,
就可用类名直接调用,
故出现Math.max();

楼上。。。。那叫API吧。。。。

static double max(double a, double b)
Returns the greater of two double values.
static float max(float a, float b)
Returns the greater of two float values.
static int max(int a, int b)
Returns the greater of two int values.
static long max(long a, long b)
Returns the greater of two long values.

你是不是要引用一个类的方法?

首先明确一下 要获得一个类必须用完整限定名
例如 java.lang.String.Split();
这样会调用字符串类的一个方