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!
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter