模块 jmc.utils
程序包 com.jmc.lang

类 BuiltIns

java.lang.Object
com.jmc.lang.BuiltIns

public class BuiltIns extends Object
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 an int value.
    static long
    abs(long a)
    Returns the absolute value of a long value.
    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.
    static double
    min(double a, double b)
    Returns the smaller of two double values.
    static float
    min(float a, float b)
    Returns the smaller of two float values.
    static int
    min(int a, int b)
    Returns the smaller of two int values.
    static long
    min(long a, long b)
    Returns the smaller of two long 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.
    printf(String format, Object... args)
    Formats a string according to a format string and writes the formatted string to the standard output stream, using the specified arguments.
    printf(Locale l, String format, Object... args)
    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
    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 closest long to the argument, with ties rounding to positive infinity.
    static int
    round(float a)
    Returns the closest int 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.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 方法详细资料

    • 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

      public static void print(String s)
      Prints a string.
      参数:
      s - the string to print
      另请参阅:
    • print

      public static void print(Object obj)
      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

      public static void println(String x)
      Prints a string and then terminate the line.
      参数:
      x - the string to print
      另请参阅:
    • println

      public static void println(Object x)
      Prints an object and then terminate the line.
      参数:
      x - the object to print
      另请参阅:
    • printf

      public static PrintStream printf(String format, Object... args)
      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 string
      args - arguments referenced by the format specifiers in the format string
      返回:
      the PrintStream object itself
      另请参阅:
    • printf

      public static PrintStream printf(Locale l, String format, Object... args)
      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. If l is null, no localization is applied.
      format - a format string
      args - 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 base
      b - the exponent
      返回:
      the value ab.
      另请参阅:
    • round

      public static int round(float a)
      Returns the closest int 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 closest long to the argument, with ties rounding to positive infinity.
      参数:
      a - a floating-point value to be rounded to a long.
      返回:
      the value of the argument rounded to the nearest long value.
      另请参阅:
    • abs

      public static int abs(int a)
      Returns the absolute value of an int 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 a long 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 two int values.
      参数:
      a - an int
      b - another int
      返回:
      the larger of a and b.
      另请参阅:
    • max

      public static long max(long a, long b)
      Returns the greater of two long values.
      参数:
      a - a long
      b - another long
      返回:
      the larger of a and b.
      另请参阅:
    • max

      public static float max(float a, float b)
      Returns the greater of two float values.
      参数:
      a - a float
      b - another float
      返回:
      the larger of a and b.
      另请参阅:
    • max

      public static double max(double a, double b)
      Returns the greater of two double values.
      参数:
      a - a double
      b - another double
      返回:
      the larger of a and b.
      另请参阅:
    • min

      public static int min(int a, int b)
      Returns the smaller of two int values.
      参数:
      a - an int
      b - another int
      返回:
      the smaller of a and b.
      另请参阅:
    • min

      public static long min(long a, long b)
      Returns the smaller of two long values.
      参数:
      a - a long
      b - another long
      返回:
      the smaller of a and b.
      另请参阅:
    • min

      public static float min(float a, float b)
      Returns the smaller of two float values.
      参数:
      a - a float
      b - another float
      返回:
      the smaller of a and b.
      另请参阅:
    • min

      public static double min(double a, double b)
      Returns the smaller of two double values.
      参数:
      a - a double
      b - another double
      返回:
      the smaller of a and b.
      另请参阅: