Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class sdss
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int anzahlSpeicher = 0;
- double[] celsius;
- double[] fahrenheit;
- final double absZero = -273.5;
- System.out.println("Wie viele Temperaturwerte wollen Sie von Celsius in Fahrenheit umwandeln?");
- try
- {
- anzahlSpeicher = input.nextInt();
- if (anzahlSpeicher <= 0)
- {
- input.close();
- throw new NegativeArraySizeException("Der Werte-Bereich muss >0 sein!");
- }
- }
- catch (InputMismatchException e)
- {
- System.out.println("Bitte nur Zahlen eingeben!");
- }
- catch (NegativeArraySizeException e)
- {
- System.out.println(e.getMessage());
- }
- celsius = new double[anzahlSpeicher];
- fahrenheit = new double[anzahlSpeicher];
- for(int i=0; i<anzahlSpeicher; i++)
- {
- try
- {
- System.out.println("Bitte Temperaturwerte für Celsius eingeben.");
- celsius[i] = input.nextDouble();
- if (celsius[i] < absZero)
- {
- throw new AbsoluteZeroException("Die Zahl darf nicht unter den absoluten Nullpunkt (-273.5°C)!");
- }
- else
- {
- fahrenheit[i] = celsiusToFahrenheit(celsius[i]);
- System.out.println(celsius[i] + "°C" + " =" + " " + fahrenheit[i] + "°F");
- }
- }
- catch (AbsoluteZeroException e)
- {
- System.out.println(e.getMessage());
- }
- catch (InputMismatchException e)
- {
- System.out.println("Bitte nur Zahlen eingeben!");
- }
- }
- input.close();
- }
- public static double celsiusToFahrenheit (double celsius)
- {
- return 9./5. * celsius + 32.;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement