Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContadorDio #26

Open
dleitte opened this issue May 10, 2024 · 0 comments
Open

ContadorDio #26

dleitte opened this issue May 10, 2024 · 0 comments

Comments

@dleitte
Copy link

dleitte commented May 10, 2024

import java.util.Scanner;

class ParametrosInvalidosException extends Exception {
public ParametrosInvalidosException(String mensagem) {
super(mensagem);
}
}

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 {
        
        if (parametroUm > parametroDois) {
            throw new ParametrosInvalidosException("O segundo parâmetro deve ser maior que o primeiro");
        }
       contar(parametroUm, parametroDois);
    } catch (ParametrosInvalidosException exception) {
        System.out.println(exception.getMessage());
    } finally {
        
        terminal.close();
    }
}

static void contar(int parametroUm, int parametroDois) {
    
    for (int i = parametroUm; i <= parametroDois; i++) {
        System.out.println("Imprimindo o número " + i);
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant