-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.txt
More file actions
47 lines (41 loc) · 861 Bytes
/
Anagram.txt
File metadata and controls
47 lines (41 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sanjaysir;
import java.util.Scanner;
public class Anagram {
public static void main(String[] args) {
int count=0;
Scanner s=new Scanner(System.in);
System.out.println("enter the 1st string");
String str1=s.nextLine();
System.out.println("enter the 2nd string");
String str2=s.nextLine();
char ch1[]=str1.toCharArray();
char ch2[]=str2.toCharArray();
if (ch1.length==ch2.length)
{
for (int i = 0; i < ch1.length; i++)
{
for (int j = 0; j < ch2.length; j++)
{
if (ch1[i]==ch2[j])
{
ch2[j]=' ';
break;
}
}
}
int k=0;
for (k = 0; k < ch2.length; k++)
{
if (ch2[k]!=' ')
{
System.out.println("not an angram");
break;
}
}
if(k==ch2.length)
{
System.out.println("anagram");
}
}
}
}