Computer scienceProgramming languagesJavaInterview preparationAlgorithms and problem solving techniques

Dynamic programming approach in action

Stair climbing

Report a typo

Imagine that there are N stairs and a person standing at the bottom. Climbing the stairs, the person can either go to the next step or jump over it. You need to count the number of different ways a person can reach the last step.

the scheme of climbing the stairs

Write a program that reads the number of stairs N from the input and prints the number of ways a person can reach the top of the stairs. N will be in the range from 1 to 15.

Sample Input 1:

2

Sample Output 1:

2

Sample Input 2:

4

Sample Output 2:

5

Sample Input 3:

6

Sample Output 3:

13
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
var scanner = new Scanner(System.in);
// put your code here
}
}
___

Create a free account to access the full topic