Find sum of the series 1 + 22 + 333 + 4444 + ... ... upto n terms | Java Program to find Sum of first n terms ; Returning the final sum ; Driver code ; no . of terms to find the sum
import java . util . * ; class solution { static int calculateSum ( int n ) { return ( ( int ) Math . pow ( 10 , n + 1 ) * ( 9 * n - 1 ) + 10 ) / ( int ) Math . pow ( 9 , 3 ) - n * ( n + 1 ) / 18 ; } public static void main ( String ar [ ] ) { int n = 3 ; System . out . println ( " Sum = ▁ " + calculateSum ( n ) ) ; } }