Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Agam
- {
- public static int subs(int[] arr)
- {
- int sum;
- int total = 0;
- for (int i = 0;i<arr.length;i++)
- {
- sum=0;
- for(int j = i;j<arr.length;j++)
- {
- sum = (sum+arr[j])%3;
- if(sum == 0)
- total++;
- }
- }
- return total;
- }
- public static void main(String args[])
- {
- int nums[] = {6,1,4,124,3,6,512,3,1,33,2,2,32,100,813,4,41,1,3,8,213,5,7,61,8,42,1,4,2,20,8};
- System.out.println(subs(nums));
- System.out.println("See?");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement