import java.util.ArrayList;
public class FindPair {
public static void main(String[] args) {
int arr[] = {1,2,4,6,3,5};
int key = 20;
findPair(arr,key);
}
private static void findPair(int[] arr, int key) {
ArrayList<Integer> numbers = new ArrayList<>();
boolean status = false;
for(int num : arr) {
int anotherNumber = (key/num);
if(numbers.contains(anotherNumber) && (anotherNumber*num) == key) {
status=true;
System.out.println("Pair Found: "+"( "+anotherNumber+", "+ num+" )");
}
numbers.add(num);
}
if(!status)
System.out.print("No such pair");
}
}
Output:-
Pair Found:- (4,5)
Wednesday, March 17, 2021
How to find pair of two numbers that's multiply equals to Key
Subscribe to:
Post Comments (Atom)
How to find middle node of LinkedList without using extra memory in java
To find the middle node of a LinkedList without using extra memory in Java, you can use the "tortoise and hare" algorithm. This al...
-
public class ReverseArrayWithoutExtraMemory { public static void main(String[] args) { int arr[] = {1,2,3,4,5,6}; int swapArray[] =...
-
1) List Interface Implementation public interface List<T extends Comparable<T>> { public Node<T> getMi...
-
function data_change(field) { var check = true; var value = field.value; //get characters //check that all ch...
No comments:
Post a Comment