


Some dates are cited as ambigrams when rendered in numerical form. A few simple examples are the numbers 808 (also a palindrome) and 609 (not a palindrome). (However, it wouldn’t be considered a traditional ambigram when it’s spelled in lowercase as noon, because when viewed upside down it looks like uoou, which isn’t commonly understood as a word or meaningful sequence.) The capitalized palindrome NOON is an example. However, many simple ambigrams are also palindromes. For example, the word MOM viewed upside down yields the word WOW (and vice versa).Īmbigrams are different from palindromes, which read the same forward and backward. Other ambigrams yield a new word, number, or sequence when viewed upside down. Such ambigrams are said to have rotational symmetry, meaning they yield the same sequence when viewed (or rotated) upside down. See?! Another example is the word dollop. NOON is a simple example of an ambigram-it still reads as NOON even when viewed upside down. Sometimes, the new orientation yields the same exact sequence of characters in the same order in other cases, it yields a different sequence (though one that is still readable or has a recognizable meaning). Here, we checked if the strings provided by users are anagram.An ambigram is a word, number, or other figure that looks the same or can still be read when viewed (or rotated) upside down. In the above example, we have used the Scanner class to take input from the user. Hence, strings should be converted to the same case.Įxample 2: Take string inputs from users and check if the strings are anagram import Note: The Arrays.sort() compares two characters with ASCII value. If sorted arrays are equal, then the strings are anagram. Arrays.equal() - checks if the sorted char array are equal.Arrays.sort() - sorts both the char arrays.str1.toCharArray() - converts the string into a char array.It is because Java is case sensitive and R and r are two difference characters in Java. We first convert the strings to lowercase. We are checking if str1 and str2 are anagrams. In Java, we have two strings named str1 and str2. (str1 + " and " + str2 + " are not anagram.") (str1 + " and " + str2 + " are anagram.") Example 1: Java program to check if two strings are anagrams import īoolean result = Arrays.equals(charArray1, charArray2) Here, we can form Race by arranging the characters of Care. Two strings are said to be anagram if we can form one string by arranging the characters of another string.
