Advertisement
Zidinjo

Untitled

Dec 7th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.InputMismatchException;
  3.  
  4.  
  5. public class sdss
  6. {
  7.         public static void main(String[] args)
  8.         {
  9.                 Scanner input = new Scanner(System.in);
  10.                 int anzahlSpeicher = 0;
  11.                 double[] celsius;
  12.                 double[] fahrenheit;
  13.                 final double absZero = -273.5;
  14.                 System.out.println("Wie viele Temperaturwerte wollen Sie von Celsius in Fahrenheit umwandeln?");
  15.                 try
  16.                 {
  17.                         anzahlSpeicher = input.nextInt();
  18.                         if (anzahlSpeicher <= 0)
  19.                         {
  20.                                 input.close();
  21.                                 throw new NegativeArraySizeException("Der Werte-Bereich muss >0 sein!");
  22.                         }
  23.                 }
  24.                 catch (InputMismatchException e)
  25.                 {
  26.                         System.out.println("Bitte nur Zahlen eingeben!");
  27.                 }
  28.                 catch (NegativeArraySizeException e)
  29.                 {
  30.                         System.out.println(e.getMessage());
  31.                 }
  32.                 celsius = new double[anzahlSpeicher];
  33.                 fahrenheit = new double[anzahlSpeicher];
  34.                
  35.                 for(int i=0; i<anzahlSpeicher; i++)
  36.                 {
  37.                         try
  38.                         {
  39.                             System.out.println("Bitte Temperaturwerte für Celsius eingeben.");
  40.                             celsius[i] = input.nextDouble();
  41.                                 if (celsius[i] < absZero)      
  42.                                 {
  43.                                         throw new AbsoluteZeroException("Die Zahl darf nicht unter den absoluten Nullpunkt (-273.5°C)!");
  44.                                 }
  45.                                 else
  46.                                 {
  47.                                 fahrenheit[i] = celsiusToFahrenheit(celsius[i]);
  48.                                 System.out.println(celsius[i] + "°C" + " =" + " " + fahrenheit[i] + "°F");
  49.                                 }
  50.                         }
  51.                         catch (AbsoluteZeroException e)
  52.                         {
  53.                                 System.out.println(e.getMessage());
  54.                         }
  55.                         catch (InputMismatchException e)
  56.                         {
  57.                                 System.out.println("Bitte nur Zahlen eingeben!");
  58.                         }
  59.                 }
  60.                 input.close();
  61.         }
  62.        
  63.         public static double celsiusToFahrenheit (double celsius)
  64.         {
  65.                 return 9./5. * celsius + 32.;
  66.         }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement