Counting length-2 substrings that are common to two strings at the same offset
If I were you I would try to write more concise solutions. Readability is extremely important. If you write code that is hard to read, it will not be reused as much, it will be hard to change or extend the code, your code will probably perform worse, and it will be hard to find bugs.

Your first approach can be based on your intuition, but then you should look at your code, and try to find ways to simplify it. With time and experience, this will get easier and easier, and your intuitive solution will more closely resemble a concise solution.

Ignoring the complexity of your solution, here are some things that could be better:


Your first two for loops perform exactly the same functionality, and you shouldn't duplicate code. Whenever you copy-paste a piece of code, think about extracting it to a method. This will increase the readability, maintainability, and reusability of your code.
define variables when they are needed, not earlier. The fewer variables a reader has to remember at any point, the easier it will be to understand your code. count for example isn't needed at the beginning of the method, but just in the last for loop, so declare it there. Another example is sub2, which isn't needed at all, and which also doesn't have a very expressive name.
use spaces around - and + to increase readability.
don't declare variables that are only used once, but use those values directly, eg arrayA[i] = a.substring(i, i+2);.
use curly brackets even for one line statements to increase readability and possibly avoid future bugs.
be consistent. Why do you use i as loop variable for the first two loops, but not the third? If there is no reason, use i for all.
Why have if (j &gt;= b.length())? It's not intuitively clear what it does, so you should at least add a comment.