SDET Interview Question and Answers.
Java Interview Question SET-01
Java INterview Question Set-02 ARRAY
Java INterview Questiona Set-03 MAP
Java INterview Question Set-04
Java is a very important topic for both developers and testers. It's very difficult to remember all the Java basics, so it's always wise to do a revision before the day of the interview.
What is Recursion in Java?
Recursion works in Java the same way it works everywhere else. Recursion is, fundamentally, the process of solving a problem by reducing it to a smaller version of itself.
Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve.
In Java, a method that calls itself is known as a recursive method. This process is also known as recursion. A physical world example would be to place two parallel mirrors facing each other. Any object in between them will be reflected recursively.
Appium Interview Questions and Answers
Selenium Interview Questions and answers.
GIT Interview Questions and Answers
Why do we need Recursion?
Recursion is made for solving problems that can be broken down into smaller, repetitive problems. It is especially good for working on things that have many possible branches and are too complex for an iterative approach . One good example of this would be searching through a file system
import java.util.Scanner;
public class recursion
{
public static void main(String[] args)
{
int n = 5;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
recursion obj = new recursion();
System.out.print("recursion numbers till "+n+" :");
obj. recursion(n,1);
}
int recursion(int y, int i)
{
if(i <= y)
{
System.out.print(i+" ");
return(recursion(y,++i));
}
return 1;
}
}
You can also find factorials using Recursion, very important for interview preparation:
Jenkins Interview Questions and Answers.
TYPES of Recursion
There are several different recursion types and terms. These include:
- Direct recursion: This is typified by the factorial implementation where the methods call itself.
- Mutual recursion: This happens where one method, say method A, calls another method B, which then calls method A. This involves two or more methods that eventually create a circular call sequence.
- Multi-recursion: Multiple recursive calls are made in the method.
- Head recursion: The recursive call is made at the beginning of the method.
- Tail recursion: The recursive call is the last statement.
Factorial of a Number Using Recursion
class Factorial {
static int factorial( int n ) {
if (n != 0) // termination condition
return n * factorial(n-1); // recursive call
else
return 1;
}
public static void main(String[] args) {
int number = 4, result;
result = factorial(number);
System.out.println(number + " factorial = " + result);
}
}
************************************************
✍️AUTHOR: LinkedIn Profile
************************************************
Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employee and LIVE Doubt Session
*************************************************
SeleniumWebdriver Automation Testing Interview Questions:
https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver
API Testing Interview Question Set:
https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html
DevOps Interview Q&A:
https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes
Docker Interview Question Set
https://automationreinvented.blogspot.com/Docker
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign
Java Related Interview Question Set
https://automationreinvented.blogspot.com/search/label/Java
GIT Interview Question Set:
https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html
Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions
Mobile Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Mobile%20Testing
Python Interview Question Set for QAE - SDET - SDE:
https://automationreinvented.blogspot.com/search/label/Python
No comments:
Post a Comment