Sum of integers upto N with given unit digit | Java implementation of the approach ; Function to return the required sum ; Driver code
class Solution { static long getSum ( int n , int d ) { long sum = 0 ; while ( d <= n ) { sum += d ; d += 10 ; } return sum ; } public static void main ( String args [ ] ) { int n = 30 , d = 3 ; System . out . print ( getSum ( n , d ) ) ; } }