+ 2

I am getting error of return statement missing ..Can anyone help ??? It's a code of anagrams

import java.util.Scanner; public class Solution { static boolean isAnagram(String a, String b) { char []c =a.toCharArray(); char []d =b.toCharArray(); for(int i=0;i<b.length();i++){ for(int j=0;j<a.length();j++){ if(c[i]==d[j]){ d[j]=' '; if(i==a.length()){ return true; } else{ break; } } else if(c[i]!=d[j]&&j==a.length()){ i=b.length(); return false; } } } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); String a = scan.next(); String b = scan.next(); scan.close(); boolean ret = isAnagram(a, b); System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );}}

25th Jun 2021, 3:46 PM
Minishreddy Vaidhyula
Minishreddy  Vaidhyula  - avatar
3 Réponses
+ 1
25th Jun 2021, 4:38 PM
Minishreddy Vaidhyula
Minishreddy  Vaidhyula  - avatar