LAST UPDATED: NOVEMBER 24, 2020
Java Character isMirrored(int codePoint) Method
Java
isMirrored(int codePoint)
is a part of Character
class. This method is used to check whether the specified Unicode code point 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 the text that is left-to-right but as a ")" in text that is right-to-left.
Syntax:
public static boolean isMirrored(int codePoint)
Parameters:
The parameter passed is the Unicode code point 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)
{
int cp1 = 48;
int cp2 = 60;
int cp3 = 119;
int cp4 = 93;
int cp5 = 1232;
boolean b1 = Character.isMirrored(cp1);
boolean b2 = Character.isMirrored(cp2);
boolean b3 = Character.isMirrored(cp3);
boolean b4 = Character.isMirrored(cp4);
boolean b5 = Character.isMirrored(cp5);
System.out.println((char)cp1 +" is mirrored??: "+b1);
System.out.println((char)cp2 +" is mirrored??: "+b2);
System.out.println((char)cp3 +" is mirrored??: "+b3);
System.out.println((char)cp4 +" is mirrored??: "+b4);
System.out.println((char)cp5 +" is mirrored??: "+b5);
}
}
0 is mirrored??: false
< is mirrored??: true
w 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 Unicode character: ");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
boolean b = Character.isMirrored(cp);
System.out.println((char)cp + " is mirrored?: "+b);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the Unicode character: 93
] is mirrored?: true
****************************************
Enter the Unicode character: 98
b is mirrored?: false
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.