Find the element at R ' th ▁ row ▁ and ▁ C ' th column in given a 2D pattern | Java implementation to compute the R ' th ▁ row ▁ and ▁ C ' th column of the given pattern ; Function to compute the R ' th ▁ row ▁ and ▁ C ' th column of the given pattern ; First element of a given row ; Element in the given column ; Driver code ; Function call
import java . io . * ; class GFG { static int findValue ( int R , int C ) { int k = ( R * ( R - 1 ) ) / 2 + 1 ; int diff = R + 1 ; for ( int i = 1 ; i < C ; i ++ ) { k = ( k + diff ) ; diff ++ ; } return k ; } public static void main ( String [ ] args ) { int R = 4 ; int C = 4 ; int k = findValue ( R , C ) ; System . out . println ( k ) ; } }