Example__2

PHOTO EMBED

Mon May 29 2023 15:38:31 GMT+0000 (Coordinated Universal Time)

Saved by @Mohamedshariif #java

import java.util.Scanner;

public class Exercise {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("How far do you want to walk (in meters):");
		int distance = scanner.nextInt();
		
		
		takeAStep(0, distance);
	
	}
	static void takeAStep(int i, int distance) {
//base case
		if(i<distance) {
			i++;
			System.out.println("*You take a step * " +i+ " meter/s.");
			takeAStep(i, distance);
		}
		else {
			System.out.println("You are done walking!");
		}
	}
	
}
//output:
How far do you want to walk (in meters):
10
*You take a step * 1 meter/s.
*You take a step * 2 meter/s.
*You take a step * 3 meter/s.
*You take a step * 4 meter/s.
*You take a step * 5 meter/s.
*You take a step * 6 meter/s.
*You take a step * 7 meter/s.
*You take a step * 8 meter/s.
*You take a step * 9 meter/s.
*You take a step * 10 meter/s.
You are done walking!
content_copyCOPY