
Patrick B. answered 03/24/21
Math and computer tutor/teacher
class ArtemisL
{
public static void main(String args[])
{
(new ArtemisL()).waysToClimb(4, 0, "[");
}
public void waysToClimb(int n, int position, String result)
{
if (n == position)
{
int index = result.lastIndexOf(",");
if (index != -1)
{
result = result.substring(0, index) + "]";
System.out.println(result);
}
}
else if (n > position)
{
waysToClimb(n, position + 1, result + "1, ");
waysToClimb(n, position + 2, result + "2, ");
}
}
}