Guest User

Untitled

a guest
Nov 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Konsole {
  4.  
  5. // Methode zum einlesen vom Datentyp 'int'
  6. // Fehlerbehandlung vorhanden
  7.  
  8. public static int readInt()
  9. {
  10. Scanner scan = new Scanner (System.in);
  11. int i = 0;
  12. boolean finish = false;
  13. while(!finish)
  14. {
  15. try
  16. {
  17. i = scan.nextInt();
  18. finish = true;
  19. }
  20. catch (Exception e)
  21. {
  22. System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
  23. scan.nextLine();
  24. }
  25. }
  26.  
  27. return i;
  28. }
  29.  
  30. // Methode zum einlesen vom Datentyp 'double'
  31. // Fehlerbehandlung vorhanden
  32.  
  33. public static double readDouble()
  34. {
  35. Scanner scan = new Scanner (System.in);
  36. double i = 0;
  37. boolean finish = false;
  38. while(!finish)
  39. {
  40. try
  41. {
  42. i = scan.nextDouble();
  43. finish = true;
  44. }
  45. catch (Exception e)
  46. {
  47. System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
  48. scan.nextLine();
  49. }
  50. }
  51. return i;
  52. }
  53.  
  54. // Methode zum einlesen vom Datentyp 'char'
  55. // Fehlerbehandlung vorhanden
  56.  
  57. public static char readChar()
  58. {
  59. Scanner scan = new Scanner (System.in);
  60. char i = '0';
  61. String k = "aaa";
  62. boolean finish = false;
  63. while(k.length() != 1)
  64. {
  65. try
  66. {
  67. k = scan.nextLine();
  68. finish = true;
  69. if(k.length() != 1)
  70. {
  71. System.out.println("Falsche Eingabe. Bitte Wiederholen");
  72. }
  73. }
  74. catch (Exception e)
  75. {
  76. System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
  77. scan.nextLine();
  78. }
  79. i = k.charAt(0);
  80. }
  81. return i;
  82. }
  83.  
  84. // Methode zum einlesen vom Datentyp 'String'
  85. // Fehlerbehandlung vorhanden
  86.  
  87. public static String readString()
  88. {
  89. Scanner scan = new Scanner (System.in);
  90. String i = null;
  91. boolean finish = false;
  92. while(!finish)
  93. {
  94. try
  95. {
  96. i = scan.nextLine();
  97. finish = true;
  98. }
  99. catch (Exception e)
  100. {
  101. System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
  102. scan.nextLine();
  103. }
  104. }
  105. return i;
  106. }
  107.  
  108. }
Add Comment
Please, Sign In to add comment