32 lines
1008 B
Java
32 lines
1008 B
Java
package de.temprechner;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class TempRechner {
|
|
|
|
//Scanner
|
|
public static void rechner() {
|
|
Scanner scan = new Scanner(System.in);
|
|
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 = ");
|
|
|
|
int auswahl = scan.nextInt();
|
|
|
|
System.out.print("Gib die Temperatur in Celsius ein: ");
|
|
double celsius = scan.nextDouble();
|
|
|
|
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();
|
|
}
|
|
} |