MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / main

Method main

Programs/Two_Sum.java:6–27  ·  view source on GitHub ↗
(String args[])

Source from the content-addressed store, hash-verified

4import java.util.*;
5public class Two_Sum {
6 public static void main(String args[])
7 {
8 try (Scanner sc = new Scanner(System.in)) {
9 int n = sc.nextInt();
10 // length of the array is taken
11 int a[] = new int[n];
12 for(int i = 0; i < n; i++)
13 {
14 a[i] = sc.nextInt();
15 }
16 int target=sc.nextInt();
17 // target value is initialzized
18 int array[] = new int[2];
19 a=twoSum(array,target);
20 // method is called
21 for(int i=0;i<2;i++)
22 {
23 System.out.print(a[i]+" ");
24 }
25 System.out.println();
26 }
27 }
28 public static int[] twoSum(int[] n, int target) {
29 Map<Integer,Integer> nm=new HashMap<>();
30 // hashmap is created to store the array elements

Callers

nothing calls this directly

Calls 2

twoSumMethod · 0.95
printMethod · 0.80

Tested by

no test coverage detected