-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercicio_9.java
More file actions
28 lines (26 loc) · 1.07 KB
/
Copy pathExercicio_9.java
File metadata and controls
28 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.InputMismatchException;
import java.util.Scanner;
class TemperaturaInvalidaException extends Exception {
public TemperaturaInvalidaException(String mensagem) {
super(mensagem);
}
}
public class Exercicio_9 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
System.out.println("Digite a temperatura em Celsius:");
double celsius = scanner.nextDouble();
if (celsius < -273.15) {
throw new TemperaturaInvalidaException("A temperatura não pode ser inferior ao zero absoluto (-273.15°C).");
}
double fahrenheit = (celsius * 9/5) + 32;
System.out.println("Temperatura em Fahrenheit: " + fahrenheit);
} catch (InputMismatchException e) {
System.out.println("Erro: Insira um número válido para a temperatura.");
scanner.next();
} catch (TemperaturaInvalidaException e) {
System.out.println("Erro: " + e.getMessage());
}
}
}