You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
}
The text was updated successfully, but these errors were encountered:
import java.util.Scanner;
class ParametrosInvalidosException extends Exception {
public ParametrosInvalidosException(String mensagem) {
super(mensagem);
}
}
public class Contador {
public static void main(String[] args) {
}
The text was updated successfully, but these errors were encountered: