In: Computer Science
Please do Part III
Part I
Problem statement:
Given an array of 'n' non-duplicate integers, find pairs of integers from the array that make the sum equal to K.
Eg. [1, 2, 7, 11, 6, 9, 5] K= 12
Soln: (1,11), (7,5).
Part II
Write an Oracle for testing this program using Data Flow Testing. As usual, write down test cases in a tabular form with reasons, inputs, expected output etc.
Part III
1. Identify the basic blocks in your program and draw the flow graph
2. Identify as many independent paths as possible with a minimum of three paths)
3. Classify these as simple paths and loop-free paths
4. Identify the definition, P-uses, and C-uses throughout the program
5. Identify the def-use associations of variables if any.
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws
IOException{
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter list of
non-duplicate values");
int[] A =
Arrays.stream(br.readLine().trim().split("
")).mapToInt(Integer::parseInt).toArray();
System.out.print("K = ");
int k =
Integer.parseInt(br.readLine().trim());
///////// Adding all list values
into a set
Set<Integer> set = new
HashSet<>();
for(int i : A)
{
set.add(i);
}
///// iterating over the set
Iterator itr =
set.iterator();
while(itr.hasNext())
{
int val = (int)itr.next();
////// for each value in set....
checking whether there is a number exists in
////// the set which can add up
with the current value to make K
if(set.contains(k-val)){
int corr_val = k - val;
if(val != corr_val)
System.out.print("(" + val + "," +
corr_val + "),");
}
itr.remove(); //// once checked ,
there is no need of number anymore. hence simply remove the number
from the set
}
}
}