当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Character.isMirrored()用法及代码示例


java.lang.Character.isMirrored()是java中的一种内置方法,该方法确定字符是否根据Unicode规范进行镜像。当以从右到左的文本显示时,镜像字符的字形应水平镜像。例如,“ \ u0028”左括号在语义上被定义为左括号。这将在从左到右的文本中显示为“(”,但在从右到左的文本中显示为“)”。镜像字符的一些示例是[] {}()等。

用法:

public static boolean isMirrored(char ch)

Parameters:
ch - char for which the mirrored property is requested

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


下面给出了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


相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 Character.isMirrored() in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。