Java Character isMirrored()及示例

Java Character isMirrored()及示例

java.lang.Character.isMirrored() 是java中的一个内置方法,根据Unicode规范确定字符是否是镜像的。镜像字符在从右到左的文本中显示时,其字形应该是水平镜像的。例如,’\u0028′ LEFT PARENTHESIS在语义上被定义为一个开口括号。这在从左到右的文本中会显示为”(“,但在从右到左的文本中则显示为”)”。一些镜像字符的例子是 [ ] { } ( ) 等。

语法

public static boolean isMirrored(char ch)

参数。
ch – 请求提供镜像属性的字符

返回: 如果字符是镜像的,该方法返回真,如果字符不是镜像的或未定义的,则返回假。

下面是Character.isMirrored()方法的说明。

程序 1 :

// Java program to demonstrate the
// Character.isMirrored() function
// When the character is a valid one.
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Assign values to ch1, ch2, ch3, ch4
        char ch1 = '[';
        char ch2 = '+';
        char ch3 = '}';
        char ch4 = '(';
  
        // Checks if the character is mirrored or not and prints
        boolean b1 = Character.isMirrored(ch1);
        System.out.println(ch1 + " is a mirrored character is " + b1);
  
        boolean b2 = Character.isMirrored(ch2);
        System.out.println(ch2 + " is a mirrored character is " + b2);
  
        boolean b3 = Character.isMirrored(ch1);
        System.out.println(ch3 + " is a mirrored character is " + b3);
  
        boolean b4 = Character.isMirrored(ch2);
        System.out.println(ch4 + " is a mirrored character is " + b4);
    }
}

输出:

[ is a mirrored character is true
+ is a mirrored character is false
} is a mirrored character is true
( is a mirrored character is false

程序2

// Java program to demonstrate the
// Character.isMirrored() function
// When the character is a invalid one.
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Assign values to ch1, ch2, ch3, ch4
        char ch1 = '4';
        char ch2 = '0';
  
        // Checks if the character is mirrored or not and prints
        boolean b1 = Character.isMirrored(ch1);
        System.out.println(ch1 + " is a mirrored character is " + b1);
  
        boolean b2 = Character.isMirrored(ch2);
        System.out.println(ch2 + " is a mirrored character is " + b2);
    }
}

输出:

4 is a mirrored character is false
0 is a mirrored character is false

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Java 参考指南