Generation

generate functionWed, 29 Jan 2025

import java.util.Scanner; public class Temperatura { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Conversor de temperaturas"); System.out.println("1. Grados centígrados a Fahrenheit"); System.out.println("2. Grados Fahrenheit a centígrados"); System.out.print("Ingrese la opción: "); int opcion = scanner.nextInt(); switch (opcion) { case 1: System.out.print("Ingrese la temperatura en grados centígrados: "); double centigrados = scanner.nextDouble(); double fahrenheit = centigradosToFahrenheit(centigrados); System.out.println(centigrados + "°C son " + fahrenheit + "°F"); break; case 2: System.out.print("Ingrese la temperatura en grados Fahrenheit: "); double fahrenheit2 = scanner.nextDouble(); double centigrados2 = fahrenheitToCentigrados(fahrenheit2); System.out.println(fahrenheit2 + "°F son " + centigrados2 + "°C"); break; default: System.out.println("Opción inválida"); } scanner.close(); } public static double centigradosToFahrenheit(double centigrados) { return (centigrados * 9/5) + 32; } public static double fahrenheitToCentigrados(double fahrenheit) { return (fahrenheit - 32) * 5/9; } } En el switch solo permitir uno de los 2 casos si no mandarle un mensaje de opcion inválida

Please keep input under 1000 characters

Want to kickstart your project?Use the new AI Studio to create your code