Minimum positive integer to divide a number such that the result is an odd | Java program to make a number odd ; Return 1 if already odd ; Check on dividing with a number when the result becomes odd Return that number ; If n is divided by i and n / i is odd then return i ; Driver code
import java . io . * ; class GFG { static int makeOdd ( int n ) { if ( n % 2 != 0 ) return 1 ; int i ; for ( i = 2 ; i <= n ; i ++ ) if ( ( n % i == 0 ) && ( ( n / i ) % 2 == 1 ) ) break ; return i ; } public static void main ( String [ ] args ) { int n = 36 ; int res = makeOdd ( n ) ; System . out . println ( res ) ; } }