+ 1
Tis is the program to check for anagram.What is the error at line 12 .
public class anagram { public static void main(String [] args){ String a="tanu"; String b="anut"; // boolean isanagram=true; if(a.length() == b.length()){ String[] s1=a.split(""); for(int i=0;i<a.length();i++) for(int j=0;j<b.length();j++) /*Line12*/ if(s1[i]=b.charAt(j)){ System.out.println("anagram"); } else System.out.println("not an anagram"); } }}
5 ответов
0
When you are checking with strings to access the elements you need to follow this syntax 👇
name of the string.charAt(name of the iterator)
And for arrays 👇
Name of array[name of iterator]
Note :- This is valid when you are using loops for finding elements
+ 1
if(s1[i]==b[j])
Use this please and then tell me if you don't get the expected output
+ 1
Atul [Inactive]
this too is producing error
+ 1
Tanu Jain My bad use a.charAt(i)==b.charAt(j)
Use this
+ 1
Thanks
This worked but don't know what was the problem in first code