📜  Java中的字符.isMirrored() 方法

📅  最后修改于: 2022-05-13 01:55:20.544000             🧑  作者: Mango

Java中的字符.isMirrored() 方法

字符.isMirrored(int codePoint)是Java中的一个内置方法,根据Unicode规范判断指定字符(Unicode代码点)是否被镜像。在从右到左的文本中显示时,镜像字符应使其字形水平镜像。例如,'\u0028' 左括号在语义上被定义为左括号。这将在从左到右的文本中显示为“(”,但在从右到左的文本中显示为“)”。

句法:

public static boolean isMirrored(int codePoint)

参数:整数类型的参数codePoint是要测试的字符(Unicode码点)。

返回值:如果字符被镜像,则此方法返回true,如果字符未镜像或未定义,则返回false。

下面的程序说明了字符.isMirrored() 方法:

方案一:

// Code to illustrate the isMirrored() method
import java.lang.*;
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Creating 2 int primitives char1, char2
        int char1 = 0x0c05, char2 = 0x013c;
  
        // Checks if character is mirrored or not and prints
        boolean bool1 = Character.isMirrored(char1);
        String str1 = "char1 represents a mirrored character is " + bool1;
        System.out.println(str1);
  
        boolean bool2 = Character.isMirrored(char2);
        String str2 = "char2 represents a mirrored character is " + bool2;
        System.out.println(str2);
    }
}
输出:
char1 represents a mirrored character is false
char2 represents a mirrored character is false

方案二:

// Code to illustrate the isMirrored() method
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Create 2 int primitives c1, c2
        int c1 = 0x0c07, c2 = 0x063c;
  
        // Checks if character is mirrored or not and prints
        boolean bool1 = Character.isMirrored(c1);
        String str1 = "c1 represents a mirrored character is " + bool1;
        System.out.println(str1);
  
        boolean bool2 = Character.isMirrored(c2);
        String str2 = "c2 represents a mirrored character is " + bool2;
        System.out.println(str2);
    }
}
输出:
c1 represents a mirrored character is false
c2 represents a mirrored character is false

参考:https: Java/lang/ 字符.html#isMirrored(int)