Split N into two integers whose addition to A and B makes them equal | Java program to implement the above approach ; Function to calculate the splitted numbers ; Calculate X ; If X is odd ; No pair is possible ; Otherwise ; Calculate X ; Calculate Y ; Driver function
import java . util . * ; class GFG { static void findPair ( int A , int B , int N ) { int X , Y ; X = N - B + A ; if ( X % 2 != 0 ) { System . out . print ( " - 1" ) ; } else { X = X / 2 ; Y = N - X ; System . out . print ( X + " ▁ " + Y ) ; } } public static void main ( String [ ] args ) { int A = 1 ; int B = 3 ; int N = 4 ; findPair ( A , B , N ) ; } }