Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ConsoleValidator {
- private static Scanner s = new Scanner(System.in);
- public static Integer getInteger() {
- Integer result;
- while (true) {
- try {
- String input = s.next();
- result = Integer.parseInt(input);
- return result;
- } catch (Exception e) {
- printErrorMessage();
- }
- }
- }
- public static Double getDouble() {
- Double result;
- while (true) {
- try {
- String input = s.next();
- result = Double.parseDouble(input);
- return result;
- } catch (Exception e) {
- printErrorMessage();
- }
- }
- }
- public static String getString() {
- return s.next();
- }
- private static void printErrorMessage() {
- System.err.println("Niepoprawna wartoลฤ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement