Question

In: Computer Science

Create a function that will return true if numbers X and Y exist within S such that X + Y = Z, return false otherwise.

Given:

 

S = [ 2, 1, 3, 4, 7, 5 ]

Z = 8

 

Create a function that will return true if numbers X and Y exist within S such that X + Y = Z, return false otherwise.

 

Code in Java 8. 

Solutions

Expert Solution

Source Code:

import java.util.Scanner;
class ex
{
   static boolean isIn(int arr[],int X)
   {
       int len=arr.length;
       boolean isFound=false;
       for(int i=0;i        {
           if(arr[i]==X)
           {
               isFound=true;
               break;
           }
       }
       return isFound;
   }
   static boolean isThere(int arr[],int X,int Y)
   {
       boolean isExist=false;
       if(isIn(arr,X) && isIn(arr,Y))
       {
           if((X+Y)==8)
               isExist=true;
       }
       return isExist;
   }
   public static void main(String[] args)
   {
       Scanner input=new Scanner(System.in);
       System.out.print("Enter the value for X:");
       int X=input.nextInt();
       System.out.print("Enter the value for Y:");
       int Y=input.nextInt();
       int arr[]=new int[]{2,1,3,4,7,5};
       boolean res=isThere(arr,X,Y);
       if(res==true)
           System.out.println("Yes there Exist.");
       else
           System.out.println("No there does not Exist.");
   }
}

sample input and output:


Related Solutions

For each of the formulas below, state whether it is true or false. a) pX,Y,Z(x,y,z)=pY(y)pZ∣Y(z∣y)pX∣Y,Z(x∣y,z)   ...
For each of the formulas below, state whether it is true or false. a) pX,Y,Z(x,y,z)=pY(y)pZ∣Y(z∣y)pX∣Y,Z(x∣y,z)       Select an option         True         False    b) pX,Y∣Z(x,y∣z)=pX(x)pY∣Z(y∣z)       Select an option         True         False    c) pX,Y∣Z(x,y∣z)=pX∣Z(x∣z)pY∣X,Z(y∣x,z)       Select an option         True         False    d) ∑xpX,Y∣Z(x,y∣z)=1       Select an option         True         False    e) ∑x∑ypX,Y∣Z(x,y∣z)=1       Select an option         True   ...
Find the positive numbers x, y and z whose sum is 100 such that x^r y^s...
Find the positive numbers x, y and z whose sum is 100 such that x^r y^s z^t is a maximum, where r, s and t are constants.
if A,B, and C are true statements and X,Y, and Z are false statements, determine which...
if A,B, and C are true statements and X,Y, and Z are false statements, determine which of the following are true : 1. ~[(B > Z) * ~ (A * Y)] 2. [A * (Z > C)] V ~ [(C > B) V ~(X * ~B)] 3. {[(A * B) > ~ (~C V ~Z)] * ( ~Y V Z)} * [(X > ~B) >A] 4. ~{[A > ~(Z > C)} > [(A * ~B) V (Y > ~Z]} *...
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if...
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if 0 ≤ x ≤ 1, 0 ≤ y ≤ 2, 0 ≤ z ≤ 2, and f(x, y, z) = 0 otherwise. (a) Find the value of the constant C. (b) Find P(X ≤ 1, Y ≤ 1, Z ≤ 1). (c) Find P(X + Y + Z ≤ 1).
Describe the level surfaces for the 3-variable function: f(x,y,z) = z/(x-y)
Describe the level surfaces for the 3-variable function: f(x,y,z) = z/(x-y)
Consider the following function: f (x , y , z ) = x 2 + y...
Consider the following function: f (x , y , z ) = x 2 + y 2 + z 2 − x y − y z + x + z (a) This function has one critical point. Find it. (b) Compute the Hessian of f , and use it to determine whether the critical point is a local man, local min, or neither? (c) Is the critical point a global max, global min, or neither? Justify your answer.
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n...
2.48. Is it true that {ax + by + cz|x, y, z ∈ Z} = {n · gcd(a, b, c)|n ∈ Z}? 2.49. What are all the integer values of e for which the Diophantine equation 18x + 14y + 63z = e has an integer solution. Find a solution for each such e. 2.50. For integers a, b and k > 0, is it true that a | b iff a^k | b^k ?
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z)...
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z) and determine whether it is maximum of minimum.
Find the maximum and minimum of the function f(x, y, z) = (x^2)(y^2)z in the region...
Find the maximum and minimum of the function f(x, y, z) = (x^2)(y^2)z in the region D = {(x, y, z)|x^2 + 2y^2 + 3z^2 ≤ 1}.
True or False. The production function f(x,y)=x^(2/3)+y^(2/3) has increasing returns to scale
True or False. The production function f(x,y)=x^(2/3)+y^(2/3) has increasing returns to scale
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT