```
public boolean checkSubarraySum(int[] nums, int k) {
int n = nums.length;
int[] sums = new int[n+1];
for (int i = 1; i <= n; i++) {
sums[i] = sums[i-1] + nums[i-1];
for (int j = 0; j < i-1; j++) {
int dif = sums[i]-sums[j];
if (dif == 0 && k == 0) return true;
else if (k == 0) continue;
else if ((sums[i]-sums[j]) % k == 0) return true;
}
}
return false;
}
```