-
-
Save raulmangolin/29ab007a06513449372e5eb7037ba1ba to your computer and use it in GitHub Desktop.
Exercícios Java Escrito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function produto(numeros) { | |
let resultado = numeros[0]; | |
for (let i = 1; i < numeros.length; i++) { | |
resultado = resultado * numeros[i] | |
} | |
return resultado; | |
} | |
// let numeros = [1, 4, 7]; | |
// produto(numeros); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function maisMenos(numeros) { | |
let resultado = []; | |
let positivo = 0; | |
let negativo = 0; | |
let zero = 0; | |
for (let i = 0; i < numeros.length; i++) { | |
if(numeros[i] > 0) { | |
positivo++; | |
} else if(numeros[i] < 0) { | |
negativo++; | |
} else { | |
zero++; | |
} | |
} | |
resultado[0] = positivo / numeros.length; | |
resultado[1] = zero / numeros.length; | |
resultado[2] = negativo / numeros.length; | |
return resultado; | |
} | |
// let numeros = [1, 2, 0, -1]; | |
// maisMenos(numeros); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function escada(altura){ | |
let lista = []; | |
for(let i = 1; i <= altura; i++){ | |
let espaco = altura - i; | |
lista.push(" ".repeat(espaco) + "#".repeat(i)); | |
} | |
return lista; | |
} | |
// escada(5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function acontece(horarios, minimo) { | |
let total = 0; | |
for (let i = 0; i < horarios.length; i++) { | |
if(horarios[i] <= 0) { | |
total++; | |
} | |
} | |
return (total >= minimo) ? true : false; | |
} | |
function aberturas(horarios, minimo) { | |
let resultado = []; | |
for (let i = 0; i < horarios.length; i++) { | |
resultado.push(acontece(horarios[i], minimo)); | |
} | |
return resultado; | |
} | |
// let alunosDaSegunda = [10, -5, 3, 0]; | |
// acontece(alunosDaSegunda, 2); | |
// acontece(alunosDaSegunda, 3); | |
// aberturas([[10, -5, 3, 0], [10, -5, 3, 0], [10, 3, 0]], 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment