Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package ch.hslu.demo;
  2.  
  3. import java.util.Scanner;
  4. import org.apache.logging.log4j.LogManager;
  5. import org.apache.logging.log4j.Logger;
  6.  
  7. /**
  8.  * Demo-Applikation
  9.  */
  10. public final class DemoApp {
  11.  
  12.     private static final Logger LOG = LogManager.getLogger(DemoApp.class);
  13.  
  14.     /**
  15.      * Privater Konstruktor.
  16.      */
  17.     private DemoApp() {
  18.     }
  19.  
  20.     /**
  21.      * Main-Methode.
  22.      * @param args Startargumente.
  23.      */
  24.     public static void main(String[] args) {
  25.         String input;
  26.         Scanner scanner = new Scanner(System.in);
  27.        
  28.         do {
  29.             System.out.println("Bitte Zahl eingeben ('exit' zum Beenden): ");
  30.             input = scanner.next();
  31.             float value;
  32.             try {
  33.                 value = Float.valueOf(input);
  34.                 System.out.println(Temperatur.createFromCelsius(value).getCelsius());
  35.             } catch (NumberFormatException e) {
  36.                 if(!input.equals("exit")) {
  37.                     LOG.error("Bitte gebe eine gültige Zahl ein.");
  38.                 }
  39.             } catch (IllegalArgumentException e) {
  40.                 LOG.error(e.getMessage());
  41.             }
  42.         } while (!input.equals("exit"));
  43.         LOG.info("Programm beendet.");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement