Advertisement
Guest User

Java

a guest
Jan 16th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class Uhrzeitrechner {
  5. public static void main(String[] args) {
  6.  
  7. System.out.println();
  8. System.out.println("Uhrzeitrechner");
  9. System.out.println();
  10. System.out.println("1: Zeitspanne berechnen");
  11. System.out.println("2: Uhrzeit erhöhen");
  12. System.out.println();
  13. System.out.println();
  14.  
  15. Scanner scanner = new Scanner(System.in);
  16.  
  17. int Eingabe;
  18.  
  19. Eingabe = scanner.nextInt();
  20.  
  21. String uhrzeit;
  22. String uhrzeit2;
  23.  
  24. int[] zt1 = new int[2];
  25. int[] zt2 = new int[2];
  26.  
  27. switch (Eingabe) {
  28.  
  29. case 1: System.out.println("Zeitpunkt 1 eingeben");
  30. scanner.nextLine();
  31. uhrzeit = scanner.nextLine();
  32. String[] zp1 = uhrzeit.split(":");
  33. System.out.println();
  34.  
  35. System.out.println("Zeitpunkt 2 eingeben");
  36. scanner.nextLine();
  37. uhrzeit2 = scanner.nextLine();
  38. String[] zp2 = uhrzeit2.split(":");
  39. System.out.println();
  40.  
  41. zt1[0] = Integer.parseInt(zp1[0]);
  42. zt1[1] = Integer.parseInt(zp1[1]);
  43. zt2[0] = Integer.parseInt(zp2[0]);
  44. zt2[1] = Integer.parseInt(zp2[1]);
  45.  
  46. if (zt1[0] < 0 || zt1[0] > 24 || zt1[1] < 0 || zt1[1] > 59 || zt2[0] < 0 || zt2[0] > 24 || zt2[1] < 0 || zt2[1] > 59) {
  47.  
  48. System.out.println("Falsche Eingabe");
  49.  
  50. };
  51.  
  52.  
  53. int teil1 = zt1[0] - zt2[0];
  54. int teil2 = zt1[1] - zt2[1];
  55.  
  56. int t1 = 0;
  57. int t2 = 0;
  58.  
  59. if (teil1 < 0) {teil1 = teil1 * (-1);};
  60. if (teil2 < 0) {teil2 = teil2 * (-1);};
  61. if (teil1 < 10) {t1 = 1;};
  62. if (teil2 < 10) {t2 = 1;};
  63.  
  64. if (t1 == 0 && t2 == 0) {System.out.println("Zeitspanne beträgt: " + teil1 + "h " + teil2 + "min"); break;};
  65.  
  66. scanner.close();
  67. break;
  68. }}}
  69.  
  70.  
  71.  
  72. ------------------------------------------------------------------------------------------------------------------------------------------
  73.  
  74.  
  75.  
  76. Exception in thread "main" java.lang.NumberFormatException: For input string: ""
  77. at java.lang.NumberFormatException.forInputString(Unknown Source)
  78. at java.lang.Integer.parseInt(Unknown Source)
  79. at java.lang.Integer.parseInt(Unknown Source)
  80. at Uhrzeitrechner.main(Uhrzeitrechner.java:43)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement