Coding Solution 08

Write a Java program to check if sum of a pair from the array is equal to a specific number.


Code:
public class Exercise22 {
static void  pairs_value(int inputArray[], int inputNumber)
  {
  System.out.println("Pairs of elements and their sum : ");
 
  for (int i =  0; i < inputArray.length; i++)
  {
  for (int j  = i+1; j < inputArray.length; j++)
  {
  if(inputArray[i]+inputArray[j] == inputNumber)
  {
  System.out.println(inputArray[i]+" + "+inputArray[j]+" =  "+inputNumber);
  }
  }
  }
  }
  
  public static void  main(String[] args)
  {
  pairs_value(new int[] {2, 7, 4, -5, 75, -60, 8, 11, 5, 20}, 15);
  
  pairs_value(new int[] {14, -15, 9, 16, 25, 5, 16, 45, 12, 8}, 30);
  
  }
}


Output:

Write a Java program to check if sum of a pair from the array is equal to a specific number
Output



Link: https://ide.geeksforgeeks.org/gP4uOj0kEV




I hereby confirm that the coding solution is written by me and complied & run at GreeksForGreeks Online Complier.


#MAR #MARACTIVITY #MARPOINTS #MAKAUT #SKFGI #CODINGSOLUTION
#mar #maractivity #marpoints #makaut #skfgi #codingsolution

Comments