Unable to submit Java solution while C++ pass


public class Solution {
public int cntBits(ArrayList A) {
long MOD = 1000000007;
long diffBits =0;
long count=0;

    for(int i =0;i<31;++i){
        for(int j =0;j<A.size();j++){
        diffBits = (diffBits + 2*count*(A.size()-count))%MOD;  
    // diffBits = (diffBits)%MOD;
    return (int)diffBits;


My above solution didn’t work if i used data type as int count=0;
while if i use the same code in cpp with int count=0; it works
not sure why it was failing in java