1
resposta

Desafio de Conversão de Temperaturas

import java.util.Scanner;

public class Graus {
    public static void main(String[] args) {
        Scanner tmp = new Scanner(System.in);
        int celsius = 0;
        boolean valido = false;

        while (!valido) {
            System.out.print("Digite a temperatura (Graus Celsius): ");
            try {
                celsius = tmp.nextInt();
                valido = true;
            } catch (Exception e) {
                System.out.println("Digite um valor válido (número inteiro).");
                tmp.nextLine();
            }
        }

        double fahrenheit = celsius * 1.8 + 32;
        int fahrenheitInt = (int) (fahrenheit);
        System.out.println("Sua temperatura em Fahrenheit é: " + fahrenheit);
        System.out.println("Sua temperatura em Fahrenheit inteiro é: " + fahrenheitInt);
        tmp.close();
    }
}

Garanta sua matrícula hoje e ganhe + 2 meses grátis

Continue sua jornada tech com ainda mais tempo para aprender e evoluir

Quero aproveitar agora
1 resposta

Olá Vinicius.
Seu código está correto.
Parabens.
Obrigado por compartilhar!