![jdiddy25](/avatars/11981.jpg)
jdiddy25
10.04.2020 •
Computers and Technology
Please help!
Consider the following code.
public void printNumbers(int x, int y) {
if (x < 5) {
System.out.println("x: " + x);
}
if (y > 5) { System.out.println("y: " + y);
}
int a = (int)(Math.random() * 10);
int b= (int)(Math.random() * 10);
if (x != y) printNumbers(a, b);
}
Which of the following conditions will cause recursion to stop with certainty?
x < 5
x < 5 or y > 5
x != y
x == y
Solved
Show answers
More tips
- H Health and Medicine What is Autism? Understanding the Basics of This Neurodevelopmental Disorder...
- F Family and Home How to Properly Use a Water Level?...
- D Dating, Love, Relationships 10 Useful Tips on How to Survive a Breakup?...
- F Food and Cooking Apple Cider Vinegar: The Ultimate Health and Beauty Solution...
- C Computers and Internet Е-head: How it Simplifies Life for Users?...
- F Family and Home How to Choose the Best Diapers for Your Baby?...
- F Family and Home Parquet or laminate, which is better?...
- L Leisure and Entertainment How to Properly Wind Fishing Line onto a Reel?...
- L Leisure and Entertainment How to Make a Paper Boat in Simple Steps...
- T Travel and tourism Maldives Adventures: What is the Best Season to Visit the Luxurious Beaches?...
Ответ:
x == y
How? :
So in this case for recursion to stop, the program needs to reach a base case. A base case is a situation where coming across that line of code will give a certain output, meaning it will definitely give an output and not go back into to the program. For example, if you have a program very similar to yours with recursion, and the program continues to run until it hits the value 1. Now, say you had specified in the code for the method that if the int (integer) value of the int variable x equals 1, the code would return 1. This situation in java would look like:
if (x == 1) return 1;
or
if (x == 1){
return 1;
}
This is what you would call a base case. Now, if you were to enter two values into the method for your code, what would you get? Let's say you enter 3 and 6 (3 for int x, and 6 for int y). In this case the value of variables x and y would satisfy the code, and recursion would occur, where outputs continue to loop until you hit a wall, where output satisfies a base case. For your situation, a base case would be where x can be less than five, y can be greater than five, but, most importantly, x and y do not satisfy the condition where x != y. If you don't know what that means, x != y means "x is not equal to y". So for the values of x and y to not not be equal (sorry if this is confusing), the values of x and y have to be equal. Now, if you were to pug in 6 and 6 in your code, you would an output of just one line - "y: 6" and nothing else. Tada! Recursion has ended since the output has satisfied a base case - "x and y are equal" i.e. x == y . Thus, the correct answer would be x == y. Hope my explanation helped.
Take care,
Somebody
Ответ:
Indian actor producer who work primarily in Tamil language movie
☃️ hope this help☃️