Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ConsoleValidator {
  4.     private static Scanner s = new Scanner(System.in);
  5.  
  6.     public static Integer getInteger() {
  7.         Integer result;
  8.         while (true) {
  9.             try {
  10.                 String input = s.next();
  11.                 result = Integer.parseInt(input);
  12.                 return result;
  13.             } catch (Exception e) {
  14.                 printErrorMessage();
  15.             }
  16.         }
  17.     }
  18.  
  19.     public static Double getDouble() {
  20.         Double result;
  21.         while (true) {
  22.             try {
  23.                 String input = s.next();
  24.                 result = Double.parseDouble(input);
  25.                 return result;
  26.             } catch (Exception e) {
  27.                 printErrorMessage();
  28.             }
  29.         }
  30.     }
  31.  
  32.     public static String getString() {
  33.         return s.next();
  34.     }
  35.  
  36.     private static void printErrorMessage() {
  37.         System.err.println("Niepoprawna wartoล›ฤ‡");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement