Java Progamming Anagrams Write a program that prompts the u

*Java Progamming - Anagrams*

Write a program that prompts the user for 2 words and determines whether the words are anagrams of each other. Two words are anagrams if they have exactly the same letters but spell different words, such as “silent” and “listen” or “meet” and “teem.”

Suggestions: prompt the userfor Strings and convert them into char arrays (using String methodtoCharArray( )). Sort the arrays and compare the results.

Solution

Answer:

Java Program :

import java.util.*;

public class Anagramcheckprogram
{
public static void main(String[] input)
{
String input1, input2;
int size, size1, size2, i, j, check=0, not_check=0;
Scanner scan = new Scanner(System.in);
  
System.out.print(\"Enter first string : \");
input1 = scan.nextLine();
System.out.print(\"Enter second string : \");
input2 = scan.nextLine();
  
size1 = input1.length();
size2 = input2.length();
      
if(size1 == size2)
{
size = size1;
for(i=0; i<size; i++)
{
check = 0;
for(j=0; j<size; j++)
{
if(input1.charAt(i) == input2.charAt(j))
{
check = 1;
break;
}
}
if(check == 0)
{
not_check = 1;
break;
}
}
if(not_check == 1)
{
System.out.print(\"Entered strings are not anagram\");
}
else
{
System.out.print(\"Entered strings are anagram\");
}
}
else
{
System.out.print(\"Entered strings should have same number of characters to be named as a

anagram\");
}
}
}

*Java Progamming - Anagrams* Write a program that prompts the user for 2 words and determines whether the words are anagrams of each other. Two words are anagra
*Java Progamming - Anagrams* Write a program that prompts the user for 2 words and determines whether the words are anagrams of each other. Two words are anagra

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site