Largest number smaller than or equal to N divisible by K | Java implementation of the above approach ; Function to find the largest number smaller than or equal to N that is divisible by k ; Driver code
import java . lang . * ; import java . util . * ; class GFG { static int findNum ( int N , int K ) { int rem = N % K ; if ( rem == 0 ) return N ; else return N - rem ; } public static void main ( String args [ ] ) { int N = 45 , K = 6 ; System . out . print ( " Largest ▁ number ▁ smaller ▁ " + " than ▁ or ▁ equal ▁ to ▁ " + N + " that is divisible by " + K + " ▁ is ▁ " + findNum ( N , K ) ) ; } }