Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Interface
- if문
- do while문
- super
- switch문
- 반복문
- while문
- Java
- 변수
- 조건문
- 형변환
- Photoshop
- 배열
- 상속
- Override
- 메서드
- Singleton
- illustrator
- Overload
- for문
- static
- expand
- After effects
- length
- 파라미터
- private
- symbol
- 멤버변수
- 클래스
- 생성자
Archives
- Today
- Total
Ms'Note
MathEX-3 본문
package study.java.helper;
/**
* 기본적인 공통 기능들을 묶어 놓은 클래스
*/
public class Util {
// -------------싱글톤 객체 생성 시작---------------
public static Util current;
public static Util getInstance() {
if(current == null) {
current = new Util();
}
return current;
}
public static void freeInstance() {
current = null;
}
private Util() {
super();
}
// -------------싱글톤 객체 생성 끝---------------
/**
* 범위를 갖는 랜덤값을 생성하여 리턴하는 메서드
* @param min - 범위 안에서의 최소값
* @param max - 범위 안에서의 최대값;
* @return num - max 안에서의 랜덤값
public int random(int min, int max) {
int num = (int) ((Math.random() * (max - min + 1)) + min);
return num;
}
}
Main03
package study.java.helper;
public class Main04 {
public static void main(String[] args) {
/** 5자리의 인증번호 생성하기 */
String authNum = "";
for(int i=0; i<5; i++) {
authNum += Util.getInstance().random(0, 9);
}
System.out.println("인증번호=" + authNum);
}
}
출력 결과
'IT > └▶Example Coding.JAVA' 카테고리의 다른 글
String-1 (0) | 2020.09.07 |
---|---|
MathEx-2 (0) | 2020.09.07 |
MathEX-1 (0) | 2020.09.04 |
OtherClassType-2 (0) | 2020.08.27 |
OtherClassType-1 (0) | 2020.08.27 |
Comments