當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。