Docsity

Ejercicios Recursivos: Factorial, Contar 7's, Orejas Conejo, Contar x's y 11's en Java, Ejercicios de Estructuras y procedimientos

Toggle sidebar
bg1
RECURSIVIDAD
Instrucciones: Resolver cada uno de los siguientes ejercicios utilizando una función
recursiva.
Entregables:
- Archivos extensión java
- Un documento pdf, con capturas de pantalla de la función recursiva implementada
(código), y capturas de los resultados de ejecución de cada una de las soluciones
realizadas para los ejercicios.
Ejercicio 1 – Factorial
Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the
result recursively (without loops).
Ejemplo:
factorial(1) → 1
factorial(2) → 2
factorial(3) → 6
Ejercicio 2 – Contar 7’s
Given a non-negative int n, return the count of the occurrences of 7 as a digit, so for
example 717 yields 2. (no loops). Note that mod (%) by 10 yields the rightmost digit (126
% 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).
Ejercicio 3 – Orejas de Conejo
We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, ..) have the
normal 2 ears. The even bunnies (2, 4, ..) we'll say have 3 ears, because they each have a
raised foot. Recursively return the number of "ears" in the bunny line 1, 2, ... n (without
loops or multiplication).
Ejemplo:
bunnyEars2(0) → 0
bunnyEars2(1) → 2
bunnyEars2(2) → 5
Ejercicio 4 – Contar x’s
Given a string, compute recursively (no loops) the number of lowercase 'x' chars in the
string.
pf2

Vista previa parcial del texto

¡Descarga Ejercicios Recursivos: Factorial, Contar 7's, Orejas Conejo, Contar x's y 11's en Java y más Ejercicios en PDF de Estructuras y procedimientos solo en Docsity!

RECURSIVIDAD

Instrucciones: Resolver cada uno de los siguientes ejercicios utilizando una función recursiva. Entregables:

  • Archivos extensión java
  • Un documento pdf, con capturas de pantalla de la función recursiva implementada (código), y capturas de los resultados de ejecución de cada una de las soluciones realizadas para los ejercicios. Ejercicio 1 – Factorial Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the result recursively (without loops). Ejemplo: factorial(1) → 1 factorial(2) → 2 factorial(3) → 6 Ejercicio 2 – Contar 7’s Given a non-negative int n, return the count of the occurrences of 7 as a digit, so for example 717 yields 2. (no loops). Note that mod (%) by 10 yields the rightmost digit ( % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). Ejercicio 3 – Orejas de Conejo We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, ..) have the normal 2 ears. The even bunnies (2, 4, ..) we'll say have 3 ears, because they each have a raised foot. Recursively return the number of "ears" in the bunny line 1, 2, ... n (without loops or multiplication). Ejemplo: bunnyEars2(0) → 0 bunnyEars2(1) → 2 bunnyEars2(2) → 5 Ejercicio 4 – Contar x’s Given a string, compute recursively (no loops) the number of lowercase 'x' chars in the string.

Ejemplo: countX("xxhixx") → 4 countX("xhixhix") → 3 countX("hi") → 0 Ejercicio 5 – Contar 11’s en un Array Given an array of ints, compute recursively the number of times that the value 11 appears in the array. We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass index+1 to move down the array. The initial call will pass in index as 0. Ejemplo: array11([1, 2, 11], 0) → 1 array11([11, 11], 0) → 2 array11([1, 2, 3, 4], 0) → 0