Largest proper fraction with sum of numerator and denominator equal to a given number | Java program to find the largest fraction a / b such that a + b is equal to given number and a < b . ; Calculate N / 2 ; ; Check if N is odd or even ; If N is odd answer will be ceil ( n / 2 ) - 1 and floor ( n / 2 ) + 1 ; If N is even check if N / 2 i . e a is even or odd ; If N / 2 is even apply the previous formula ; If N / 2 is odd answer will be ceil ( N / 2 ) - 2 and floor ( N / 2 ) + 2 ; Driver code
class GFG { public static void solve ( int n ) { double a = n / 2 ; if ( n % 2 != 0 ) { System . out . println ( ( Math . ceil ( a ) - 1 ) + " ▁ " + ( Math . floor ( a ) + 1 ) ) ; } else { if ( ( int ) ( a ) % 2 == 0 ) { System . out . println ( ( Math . ceil ( a ) - 1 ) + " ▁ " + ( Math . floor ( a ) + 1 ) ) ; } else { System . out . println ( ( Math . ceil ( a ) - 2 ) + " ▁ " + ( Math . floor ( a ) + 2 ) ) ; } } } public static void main ( String [ ] args ) { int n = 34 ; solve ( n ) ; } }