spielekonsole spiel ausgeschrieben & TempRechner von Celsius zu Fahrenheit und Kelvin

This commit is contained in:
2025-02-26 08:56:57 +01:00
parent fbf9a10673
commit 1180e9887e
3 changed files with 24 additions and 17 deletions

View File

@@ -5,21 +5,28 @@ import java.util.Scanner;
public class TempRechner {
//Scanner
public static void fahrenheitEingabe() {
public static void rechner() {
Scanner scan = new Scanner(System.in);
System.out.print("Bitte gib die Temperatur in Fahrenheit ein: ");
double fahrenheit = scan.nextDouble();
System.out.println("Was willst du umrechnen?");
System.out.println("1: Celsius zu Fahrenheit");
System.out.println("2: Celsius zu Kelvin");
System.out.print("Deine Wahl = ");
celsiusZuFahrenheit(fahrenheit);
}
int auswahl = scan.nextInt();
//Fahrenheit zu Celsius
public static double fahrenheitzuCelsius(double fahrenheit) {
return (fahrenheit - 32) * 1.8;
}
System.out.print("Gib die Temperatur in Celsius ein: ");
double celsius = scan.nextDouble();
//Celsius zu Fahrenheit
public static double celsiusZuFahrenheit(double celsius) {
return (celsius * 1.8) + 32;
if (auswahl == 1) {
double fahrenheit = (celsius * 1.8) + 32;
System.out.println(celsius + " °C entsprechen " + fahrenheit + " °F.");
} else if (auswahl == 2) {
double kelvin = celsius + 273.15;
System.out.println(celsius + " °C entsprechen " + kelvin + " K.");
} else {
System.out.println("Ungültige Auswahl! Bitte starte das Programm erneut.");
}
scan.close();
}
}