+ 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");                     }            }}

10th Oct 2021, 12:37 PM
Tanu Jain
5 Answers
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
10th Oct 2021, 2:15 PM
Atul [Inactive]
+ 1
if(s1[i]==b[j]) Use this please and then tell me if you don't get the expected output
10th Oct 2021, 12:59 PM
Atul [Inactive]
+ 1
Atul [Inactive] this too is producing error
10th Oct 2021, 1:39 PM
Tanu Jain
+ 1
Tanu Jain My bad use a.charAt(i)==b.charAt(j) Use this
10th Oct 2021, 1:50 PM
Atul [Inactive]
+ 1
Thanks This worked but don't know what was the problem in first code
10th Oct 2021, 2:11 PM
Tanu Jain