java.lang.Object
com.jmc.lang.BuiltIns
Java内置函数
- 从以下版本开始:
- 3.8
- API Note:
import static com.jmc.lang.Builtins.*; // In JDK 21 void main() { print(666); println(); printf("%d + %d = %d\n", 3, 4, 3 + 4); println(sqrt(9)); println(pow(2, 5)); println(round(3.4f)); println(round(4.7d)); println(abs(-3)); println(max(3, 4)); println(min(-1, 2)); }
-
方法概要
修饰符和类型方法说明static int
abs
(int a) Returns the absolute value of anint
value.static long
abs
(long a) Returns the absolute value of along
value.static double
max
(double a, double b) Returns the greater of twodouble
values.static float
max
(float a, float b) Returns the greater of twofloat
values.static int
max
(int a, int b) Returns the greater of twoint
values.static long
max
(long a, long b) Returns the greater of twolong
values.static double
min
(double a, double b) Returns the smaller of twodouble
values.static float
min
(float a, float b) Returns the smaller of twofloat
values.static int
min
(int a, int b) Returns the smaller of twoint
values.static long
min
(long a, long b) Returns the smaller of twolong
values.static double
pow
(double a, double b) Returns the value of the first argument raised to the power of the second argument.static void
print
(boolean b) Prints a boolean value.static void
print
(char c) Prints a character.static void
print
(char[] s) Prints an array of characters.static void
print
(double d) Prints a double-precision floating-point number.static void
print
(float f) Prints a floating-point number.static void
print
(int i) Prints an integer.static void
print
(long l) Prints a long integer.static void
Prints an object.static void
Prints a string.static PrintStream
Formats a string according to a format string and writes the formatted string to the standard output stream, using the specified arguments.static PrintStream
Formats a string according to a format string and the specified locale, then writes the formatted string to the standard output stream, using the specified arguments.static void
println()
Terminates the current line by writing the line separator string.static void
println
(boolean x) Prints a boolean value and then terminate the line.static void
println
(char x) Prints a character and then terminate the line.static void
println
(char[] x) Prints an array of characters and then terminate the line.static void
println
(double x) Prints a double-precision floating-point number and then terminate the line.static void
println
(float x) Prints a floating-point number and then terminate the line.static void
println
(int x) Prints an integer and then terminate the line.static void
println
(long x) Prints a long integer and then terminate the line.static void
Prints an object and then terminate the line.static void
Prints a string and then terminate the line.static long
round
(double a) Returns the closestlong
to the argument, with ties rounding to positive infinity.static int
round
(float a) Returns the closestint
to the argument, with ties rounding to positive infinity.static double
sqrt
(double a) Returns the correctly rounded positive square root of a double value.
-
方法详细资料
-
print
public static void print(boolean b) Prints a boolean value.- 参数:
b
- the boolean to print- 另请参阅:
-
print
public static void print(char c) Prints a character.- 参数:
c
- the character to print- 另请参阅:
-
print
public static void print(int i) Prints an integer.- 参数:
i
- the integer to print- 另请参阅:
-
print
public static void print(long l) Prints a long integer.- 参数:
l
- the long integer to print- 另请参阅:
-
print
public static void print(float f) Prints a floating-point number.- 参数:
f
- the float to print- 另请参阅:
-
print
public static void print(double d) Prints a double-precision floating-point number.- 参数:
d
- the double to print- 另请参阅:
-
print
public static void print(char[] s) Prints an array of characters.- 参数:
s
- the array of characters to print- 另请参阅:
-
print
Prints a string.- 参数:
s
- the string to print- 另请参阅:
-
print
Prints an object.- 参数:
obj
- the object to print- 另请参阅:
-
println
public static void println()Terminates the current line by writing the line separator string.- 另请参阅:
-
println
public static void println(boolean x) Prints a boolean value and then terminate the line.- 参数:
x
- the boolean to print- 另请参阅:
-
println
public static void println(char x) Prints a character and then terminate the line.- 参数:
x
- the character to print- 另请参阅:
-
println
public static void println(int x) Prints an integer and then terminate the line.- 参数:
x
- the integer to print- 另请参阅:
-
println
public static void println(long x) Prints a long integer and then terminate the line.- 参数:
x
- the long integer to print- 另请参阅:
-
println
public static void println(float x) Prints a floating-point number and then terminate the line.- 参数:
x
- the float to print- 另请参阅:
-
println
public static void println(double x) Prints a double-precision floating-point number and then terminate the line.- 参数:
x
- the double to print- 另请参阅:
-
println
public static void println(char[] x) Prints an array of characters and then terminate the line.- 参数:
x
- the array of characters to print- 另请参阅:
-
println
Prints a string and then terminate the line.- 参数:
x
- the string to print- 另请参阅:
-
println
Prints an object and then terminate the line.- 参数:
x
- the object to print- 另请参阅:
-
printf
Formats a string according to a format string and writes the formatted string to the standard output stream, using the specified arguments.- 参数:
format
- a format stringargs
- arguments referenced by the format specifiers in the format string- 返回:
- the PrintStream object itself
- 另请参阅:
-
printf
Formats a string according to a format string and the specified locale, then writes the formatted string to the standard output stream, using the specified arguments.- 参数:
l
- the locale to apply during formatting. Ifl
isnull
, no localization is applied.format
- a format stringargs
- arguments referenced by the format specifiers in the format string- 返回:
- the PrintStream object itself
- 另请参阅:
-
sqrt
public static double sqrt(double a) Returns the correctly rounded positive square root of a double value.- 参数:
a
- a value- 返回:
- the positive square root of
a
- 另请参阅:
-
pow
public static double pow(double a, double b) Returns the value of the first argument raised to the power of the second argument.- 参数:
a
- the baseb
- the exponent- 返回:
- the value
a
b
. - 另请参阅:
-
round
public static int round(float a) Returns the closestint
to the argument, with ties rounding to positive infinity.- 参数:
a
- a floating-point value to be rounded to an integer.- 返回:
- the value of the argument rounded to the nearest
int
value. - 另请参阅:
-
round
public static long round(double a) Returns the closestlong
to the argument, with ties rounding to positive infinity.- 参数:
a
- a floating-point value to be rounded to along
.- 返回:
- the value of the argument rounded to the nearest
long
value. - 另请参阅:
-
abs
public static int abs(int a) Returns the absolute value of anint
value.- 参数:
a
- the argument whose absolute value is to be determined- 返回:
- the absolute value of
a
. - 另请参阅:
-
abs
public static long abs(long a) Returns the absolute value of along
value.- 参数:
a
- the argument whose absolute value is to be determined- 返回:
- the absolute value of
a
. - 另请参阅:
-
max
public static int max(int a, int b) Returns the greater of twoint
values.- 参数:
a
- anint
b
- anotherint
- 返回:
- the larger of
a
andb
. - 另请参阅:
-
max
public static long max(long a, long b) Returns the greater of twolong
values.- 参数:
a
- along
b
- anotherlong
- 返回:
- the larger of
a
andb
. - 另请参阅:
-
max
public static float max(float a, float b) Returns the greater of twofloat
values.- 参数:
a
- afloat
b
- anotherfloat
- 返回:
- the larger of
a
andb
. - 另请参阅:
-
max
public static double max(double a, double b) Returns the greater of twodouble
values.- 参数:
a
- adouble
b
- anotherdouble
- 返回:
- the larger of
a
andb
. - 另请参阅:
-
min
public static int min(int a, int b) Returns the smaller of twoint
values.- 参数:
a
- anint
b
- anotherint
- 返回:
- the smaller of
a
andb
. - 另请参阅:
-
min
public static long min(long a, long b) Returns the smaller of twolong
values.- 参数:
a
- along
b
- anotherlong
- 返回:
- the smaller of
a
andb
. - 另请参阅:
-
min
public static float min(float a, float b) Returns the smaller of twofloat
values.- 参数:
a
- afloat
b
- anotherfloat
- 返回:
- the smaller of
a
andb
. - 另请参阅:
-
min
public static double min(double a, double b) Returns the smaller of twodouble
values.- 参数:
a
- adouble
b
- anotherdouble
- 返回:
- the smaller of
a
andb
. - 另请参阅:
-