Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaCharacter.isMirrored() in Java with examples

Character.isMirrored() in Java with examples

java.lang.Character.isMirrored() is an inbuilt method in java that determines whether the character is mirrored according to the Unicode specification. Mirrored characters should have their glyphs horizontally mirrored when displayed in text that is right-to-left. For example, ‘\u0028’ LEFT PARENTHESIS is semantically defined to be an opening parenthesis. This will appear as a “(” in text that is left-to-right but as a “)” in text that is right-to-left. Some examples of mirrored characters are [ ] { } ( ) etc.

Syntax:

public static boolean isMirrored(char ch)

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

Returns: This method returns true if the char is mirrored else it returns false if the character is not mirrored or undefined.

Given below is the illustration of Character.isMirrored() method:

Program 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);
    }
}


Output:

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

Program 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);
    }
}


Output:

4 is a mirrored character is false
0 is a mirrored character is false
RELATED ARTICLES

Most Popular

Recent Comments