Sum numbers divisible by 3
Java
Easy
5 views
Problem Description
Task: return sum of numbers from 1..n that are divisible by 3. Use loop and if condition.
Output Format
Return value
Official Solution
static long sumDivBy3(int n){long s=0;for(int i=1;i<=n;i++) if(i%3==0) s+=i;return s;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!