Question

(Java) - Write a recursive program that takes array of number and an integer, and returns...

(Java) - Write a recursive program that takes array of number and an integer, and returns true if the integer is in the array or false if the integer is not in the array

1 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

public class Test{
public static boolean findNum(int arr[],int n,int num)
{
if(n==0)
return false;
else
return arr[n-1]==num||findNum(arr,n-1,num);
}
public static void main(String []args){
int arr[]={2,3,4,1,7};
System.out.println(findNum(arr,5,3));
System.out.println(findNum(arr,5,0));
  
}
}

L.lt Result Sjavac Test.java N Sjava -Xmx128M -Xms16M Test true false . Execute > Share Source File STDIN public class Test{

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
(Java) - Write a recursive program that takes array of number and an integer, and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT