Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exam;
- import java.util.Scanner;
- public class UserInput {
- private static Scanner scan = new Scanner(System.in);
- public static int getInt() {
- return getInt("");
- }
- public static int getInt(String msg) {
- System.out.println(msg);
- if (scan.hasNextInt()) {
- return scan.nextInt();
- } else {
- scan.next();
- System.out.println("Niepoprawne dane");
- }
- return getInt(msg);
- }
- public static String getString(String msg) {
- System.out.println(msg);
- return scan.next();
- }
- }
Add Comment
Please, Sign In to add comment