Created
August 3, 2017 20:27
-
-
Save lucasapoena/cb7b9451322f831f9b116b8b98dc23d9 to your computer and use it in GitHub Desktop.
Classe referente ao Módulo02 - Exercício05 - Triadworks CrossCode
This file contains 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
import java.util.Scanner; | |
/* | |
* Exercicio 05 - Triadworks - CrossCode | |
* | |
* Autor: Lucas Apoena - [email protected] | |
* | |
* Descrição: | |
* Crie um código no qual imprime a uma pirâmide utilizando o símbolo # a partir de um número digitado pelo usuário. | |
* Por exemplo, se o usuário digitar o número 10 você deve gerar uma pirâmide de altura 10 como no exemplo na imagem em anexo. | |
* | |
*/ | |
public class Modulo02Exercicio05 { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Qual a altura da pirâmide? "); | |
desenhaPiramide(scanner.nextInt()); | |
} | |
private static void desenhaPiramide(int altura) { | |
int colunas = altura - 1; | |
for (int i = 0; i < altura * 2; i++) { | |
if (i % 2 != 0) { | |
for (int j = 0; j < i; j++) { | |
System.out.print("#"); | |
} | |
System.out.println(); | |
} else { | |
for (int j = 0; j < colunas; j++) { | |
System.out.print(" "); | |
} | |
colunas--; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment