diff --git a/desafios/controle-fluxo/DesafioControleFluxo/README.md b/desafios/controle-fluxo/DesafioControleFluxo/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/desafios/controle-fluxo/DesafioControleFluxo/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/desafios/controle-fluxo/DesafioControleFluxo/src/Contador.java b/desafios/controle-fluxo/DesafioControleFluxo/src/Contador.java new file mode 100644 index 0000000..9bc6445 --- /dev/null +++ b/desafios/controle-fluxo/DesafioControleFluxo/src/Contador.java @@ -0,0 +1,32 @@ +import java.util.Scanner; + +public class Contador { + public static void main(String[] args) { + Scanner terminal = new Scanner(System.in); + System.out.println("Digite o primeiro parâmetro"); + int parametroUm = terminal.nextInt(); + System.out.println("Digite o segundo parâmetro"); + int parametroDois = terminal.nextInt(); + + try { + //chamando o método contendo a lógica de contagem + contar(parametroUm, parametroDois); + + }catch (ParametrosInvalidosException exception) { + System.err.println("*** O segundo parâmetro deve ser maior que o primeiro ***"); + } + + } + static void contar(int parametroUm, int parametroDois ) throws ParametrosInvalidosException { + if(parametroUm <= parametroDois){ + int contagem = parametroDois - parametroUm; + + for(int i = 0; i <= contagem ; i++){ + System.out.print(" | "+i); + } + }else{ + throw new ParametrosInvalidosException(); + } + + } +} diff --git a/desafios/controle-fluxo/DesafioControleFluxo/src/ParametrosInvalidosException.java b/desafios/controle-fluxo/DesafioControleFluxo/src/ParametrosInvalidosException.java new file mode 100644 index 0000000..280f024 --- /dev/null +++ b/desafios/controle-fluxo/DesafioControleFluxo/src/ParametrosInvalidosException.java @@ -0,0 +1,3 @@ +public class ParametrosInvalidosException extends Exception{ + +}