Ejercicio
Conversión
Objetivo
Cree un programa en java para convertir de grados Celsius a Kelvin y Fahrenheit: le pedirá al usuario la cantidad de grados Celsius y utilizando las siguientes tablas de conversión:
Kelvin = Celsius + 273
Fahrenheit = Celsius x 18 / 10 + 32
Código de Ejemplo
// Importing the Scanner class to handle input from the useimport java.util.Scanner; // Import Scanner class for input
public class Program {
// Main entry point of the program
public static void main(String[] args) {
// Create a scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Ask the user to input the temperature in Celsius
System.out.print("Enter the temperature in Celsius: ");
// Read the user's input as a double
double celsius = scanner.nextDouble();
// Convert Celsius to Kelvin using the formula
double kelvin = celsius + 273;
// Convert Celsius to Fahrenheit using the formula
double fahrenheit = celsius * 1.8 + 32;
// Display the equivalent temperature in Kelvin
System.out.println("Temperature in Kelvin: " + kelvin);
// Display the equivalent temperature in Fahrenheit
System.out.println("Temperature in Fahrenheit: " + fahrenheit);
// Close the scanner to free up resources
scanner.close();
}
}