유틸리티 메소드

package day8;

import java.util.Scanner;

public class Util {
	// 숫자 체크 메소드

	public int numberCheck() {
		int result;
		Scanner sc = new Scanner(System.in);
		while (true) {
			if (sc.hasNextInt()) { // 입력한 값이 숫자면
				result = sc.nextInt();
				break;
			} else {
				System.out.print("숫자만 입력>");
				sc.nextLine();
			}

		}
		return result; // 입력한 값을 result에 저장
	}

	public int numberCheck1(String str) {
		int result;
		Scanner sc = new Scanner(System.in);
		while (true) {
			if (sc.hasNextInt()) { // 입력한 값이 숫자면
				result = sc.nextInt();
				break;
			} else {
				System.out.print(str + "는 숫자만 입력>");
				sc.nextLine();
			}

		}
		return result; // 입력한 값을 result에 저장
	}

	// str는 i자 이내 체크 함수
	public String lengthCheck(String str, int maxLength) {
		Scanner sc = new Scanner(System.in);
		System.out.print(str+"입력 >");
		String result;
		result = sc.next();
		while (true) {
			if (result.length() <= maxLength) {
				break;
			} else {
				System.out.println(str + "(은)는 " + maxLength + "자리 이내로 입력해주세요");
				result = sc.next();
			}
		}
		return result;
	}

}
package day8;

import java.util.List;
import java.util.Scanner;

public class Util2 {
	Scanner sc = new Scanner(System.in);
	
	//숫자체크
	public int numCheck() {
		int result;
		while(true) {
			if(sc.hasNextInt()) {
				result = sc.nextInt();
				break;
			}else {
				System.out.print("숫자만 입력> ");
				sc.nextLine();
			}
		}
		return result;
	}
	
	// 아이디 길이체크 메소드
	public String lengCheck(int max) {
		String result;
		while(true) {
			result = sc.next();
			if(result.length() > max) {
				System.out.print("길이는 최대 "+max+"까지> ");
			}else {
				break;
			}
		}
		return result;
	}
	// 아이디 중복체크 메소드
	public String duCheck(List<User2> list) {
		String result;
		while(true) {
			result = sc.next();
			boolean find = false;
			for(User2 u : list) {
				if(u.getId().equals(result)) {
					System.out.print("중복된 아이디입니다 다시입력> ");
					find = true;
					break;
				}
			}
			if(!
find) { break; } } return result; } }

각각 util과 util2 메소드를 사용하여 로그인 시스템에서 사용할 메소드를 만들었습니다.