Find the sum of elements of the Matrix generated by the given rules | JAVA implementation of the approach ; Function to return the required sum ; To store the sum ; For every row ; Update the sum as A appears i number of times in the current row ; Update A for the next row ; Return the sum ; Driver code
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int sum ( int A , int B , int R ) { int sum = 0 ; for ( int i = 1 ; i <= R ; i ++ ) { sum = sum + ( i * A ) ; A = A + B ; } return sum ; } public static void main ( String [ ] args ) throws java . lang . Exception { int A = 5 , B = 3 , R = 3 ; System . out . print ( sum ( A , B , R ) ) ; } }