فكرة الكود أنه يطلب من المستخدم أن يدخل 2 strings ثم بعد ذلك يحسب عدد مرات حدوث الأول داخل الثاني أنا حاولت في هذ1ا الكود لكن لا يعمل بشكل جيد أرجو المساعدة
public class Main {
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
System.out.println("Enter Two stings ");
System.out.println();
String str1 = console.nextLine();
String str2 = console.nextLine();
print (count (str1,str2 ));
}
public static int count (String x, String y)
{
int num = x.replaceAll(x ,y).length();
return(num);
}
public static void print (int b)
{
System.out.println("The Number of occrrunces is " +b);
}
}