1
resposta

[Desafio] Conversão de temperaturas

Um desafio a parte foi escrever Fahrenheit sem pegar cola.

O Código ficou assim:

public class TemperatureConverter {
    public static void main(String[] args) {
        
        double celsius = 23.5;
        double fahrenheit = (celsius * 1.8) + 32;
        double kelvin = celsius + 273.15;
        String tempMessage = String.format("Está %.2f graus Celcius, %.2f graus Fahrenheit e %.2f kelvin", celsius, fahrenheit, kelvin);
        System.out.println(tempMessage);

        int celsiusInteger = (int) celsius;
        System.out.println("A temperatura inteira em Celcius (ºC) é: " + celsiusInteger);

        int fahrenheitInteger = (int) fahrenheit;
        System.out.println("A temperatura inteira em Fahrenheit (ºF) é: " + fahrenheitInteger);

        int kelvinInteger = (int) kelvin;
        System.out.println("A temperatura inteira em Kelvin (K) é: " + kelvinInteger);
    }
}

Uma imagem de demonstração do resultado do código acima

Um pouco atrasado, mas seguimos!

1 resposta

Oi, Victor! Como vai?

Você estruturou muito bem a conversão entre as três escalas de temperatura. O uso do String.format deixou a mensagem clara e elegante no terminal. E a ideia de exibir os valores inteiros também mostra um bom domínio sobre o tipo int e conversão de dados.

Bons estudos!