For this Question: Count the number of substrings in the string s that are equivalent to "ab". The string s contains only the characters "a" and "b".The first line contains string s.

<b>Constraints</b>
n==s. length
1 &le; n &le; 10<sup>5</sup>Print the count of substrings in the string s that are equivalent to "ab".Sample 1:
Input:
abababaa
Output:
3, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
    public static int fun(String s) {
        int n=s.length();
        int ans=0;
        for(int i=1;i<n;i++){
            if(s.charAt(i-1)=='a'&&s.charAt(i)=='b'){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        int n=s.length();
        assert n>=1&&n<=100000 : "Input not valid";
        System.out.print(fun(s));
        
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?