Recent Posts

4Score(s)
0Comment(s)
11View(s)
4Score(s)
0Comment(s)
14View(s)

no image
import Java.util.Arrays;
public class Anagram
{
static void main (String [] args) {  
        String str1="Brag";  
        String str2="Grab";  
  
        //Converting both the string to lower case.  
        str1 = str1.toLowerCase();  
        str2 = str2.toLowerCase();  
  
        //Checking for the length of strings  
        if (str1.length() != str2.length()) {  
            System.out.println("Both the strings are not anagram");  
        }  
        else {  
            //Converting both the arrays to character array  
            char[] string1 = str1.toCharArray();  
            char[] string2 = str2.toCharArray();  
  
            //Sorting the arrays using in-built function sort ()  
            Arrays.sort(string1);  
            Arrays.sort(string2);  
  
            //Comparing both the arrays using in-built function equals ()  
            if(Arrays.equals(string1, string2) == true) {  
                System.out.println("Both the strings are anagram");  
            }  
            else {  
                System.out.println("Both the strings are not anagram");  
            }  
        }  
    }  
}  

What is the output of the above program?

Posted on February 04,2023 at 09:07 PM by Archana Digraj
14Score(s)
0Comment(s)
52View(s)
0Score(s)
0Comment(s)
2View(s)
17Score(s)
2Comment(s)
38View(s)