Hallo, ich bin dabei, einen kleinen Temperaturumrechner zu programmieren, der mit Double-werten arbeitet und auf eine Nachkommastelle gerundet ausgibt.
Jedoch sind die Werte nicht richtig. Hat jemand eine Idee warum?
Bin am verzweifeln.
import java.util.Scanner;
public class UmrechnerFC {
public static void main(String[] args) {
System.out.println("Ausgangsmaß? 1 für Fahrenheit, 2 für Celsius.");
int wahl;
Scanner einsOderZwei = new Scanner(System.in);
wahl = einsOderZwei.nextInt();
switch (wahl){
case 1:{
System.out.println("Wie viel Grad Fahrenheit sind es?");
double input;
Scanner scan = new Scanner(System.in);
input=scan.nextDouble();
double celsius = ((input-32)*(5/9));
// celsius = Math.round(celsius*10)/10.0;
System.out.printf("Das sind %f Grad Celsius", celsius);
break;
}
case 2:{
System.out.println("Wie viel Grad Celsius sind es?");
double input;
Scanner scan = new Scanner(System.in);
input=scan.nextDouble();
double fahrenheit = (input*9)/5 +32;
//fahrenheit = Math.round(fahrenheit*10)/10.0;
System.out.printf("Das sind %.1f Grad Fahrenheit", fahrenheit);
//System.out.println(fahrenheit);
break;
}
default: {
System.out.println("ERROR: Eingabe nicht 1 oder 2");
break;
}
}
}
}
Jedoch sind die Werte nicht richtig. Hat jemand eine Idee warum?
Bin am verzweifeln.
import java.util.Scanner;
public class UmrechnerFC {
public static void main(String[] args) {
System.out.println("Ausgangsmaß? 1 für Fahrenheit, 2 für Celsius.");
int wahl;
Scanner einsOderZwei = new Scanner(System.in);
wahl = einsOderZwei.nextInt();
switch (wahl){
case 1:{
System.out.println("Wie viel Grad Fahrenheit sind es?");
double input;
Scanner scan = new Scanner(System.in);
input=scan.nextDouble();
double celsius = ((input-32)*(5/9));
// celsius = Math.round(celsius*10)/10.0;
System.out.printf("Das sind %f Grad Celsius", celsius);
break;
}
case 2:{
System.out.println("Wie viel Grad Celsius sind es?");
double input;
Scanner scan = new Scanner(System.in);
input=scan.nextDouble();
double fahrenheit = (input*9)/5 +32;
//fahrenheit = Math.round(fahrenheit*10)/10.0;
System.out.printf("Das sind %.1f Grad Fahrenheit", fahrenheit);
//System.out.println(fahrenheit);
break;
}
default: {
System.out.println("ERROR: Eingabe nicht 1 oder 2");
break;
}
}
}
}