import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int o;
do {
try {
System.out.println("=== Temperaturas ===\n" +
"1. Convertir a Fahrenheit\n" +
"2. Convertir a Kelvin\n" +
"3. Salir\n" +
"Opción:");
o = Integer.parseInt(br.readLine());
if (o == 1 || o == 2) {
System.out.println("Intro los Grados:");
double v = Double.parseDouble(br.readLine());
System.out.println(v + " ºC son " + String.format("%.2f", convertirTemperaturaEscala(o, v)) + (o == 1 ? " ºF" : " K"));
} else if (o == 3) {
System.out.println("Me despido!");
} else {
System.out.println("Opción no válida!");
}
} catch (IOException | NumberFormatException e) {
System.out.println("Sólo se admiten valores numéricos");
o = 0;
}
}
while (o != 3);
}
private static double convertirTemperaturaEscala(double o, double v) {
if (o == 1) {
return 1.8 * v + 32;
} else {
return v + 273.15;
}
}
}
[/aux_code]
Grados F – K
con
No hay comentarios
[aux_code language=»javascript» theme=»tomorrow» title=»Grados F – K» extra_classes=»»]