LAST UPDATED: NOVEMBER 24, 2020
Java Character isMirrored(char ch) Method
Java
isMirrored(char ch)
is a part of Character
class. This method is used to check whether the specified character is mirrored as per the Unicode specification or not.
A character is said to be mirrored if their glyphs are 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.
Syntax:
public static boolean isMirrored(char ch)
Parameters:
The parameter passed is the character to be checked whether it is mirrored or not.
Returns:
Returns the boolean value true
if the specified character is mirrored else return false
.
Example 1:
Here, the characters are checked whether they are mirrored or not.
public class StudyTonight
{
public static void main(String[] args)
{
char ch1 = '{';
char ch2 = 'c';
char ch3 = '8';
char ch4 = '[';
char ch5 = '%';
boolean b1 = Character.isMirrored(ch1);
boolean b2 = Character.isMirrored(ch2);
boolean b3 = Character.isMirrored(ch3);
boolean b4 = Character.isMirrored(ch4);
boolean b5 = Character.isMirrored(ch5);
System.out.println(ch1 +" is mirrored??: "+b1);
System.out.println(ch2 +" is mirrored??: "+b2);
System.out.println(ch3 +" is mirrored??: "+b3);
System.out.println(ch4 +" is mirrored?? : "+b4);
System.out.println(ch5 +" is mirrored??: "+b5);
}
}
{ is mirrored??: true
c is mirrored??: false
8 is mirrored??: false
[ is mirrored?? : true
% is mirrored??: false
Example 2:
Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.
import java.util.Scanner;
public class StudyTonight
{
public static void main(String[] args)
{
try
{
System.out.print("Enter the character: ");
Scanner sc = new Scanner(System.in);
char ch = sc.next().charAt(0);
boolean b = Character.isMirrored(ch);
System.out.println(ch + " is Mirrored?: "+b);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the character: +
+ is mirrored?: false
****************************************
Enter the character: (
( is a mirrored?: true
Live Example:
Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.