Skip to content

Instantly share code, notes, and snippets.

@dongsub-joung
Created July 3, 2023 10:14
Show Gist options
  • Save dongsub-joung/0c6b08f81189b5d74542faff5ede77c6 to your computer and use it in GitHub Desktop.
Save dongsub-joung/0c6b08f81189b5d74542faff5ede77c6 to your computer and use it in GitHub Desktop.
정동섭
//정동섭
import java.util.Random;
import java.util.Scanner;
public class MyNumber {
private int birthday_yyyy;
private int birthday_mm;
private int birthday_dd;
private boolean sex;
MyNumber(){
try(Scanner sc= new Scanner(System.in)){
System.out.printf("출생년도를 입력해 주세요.(yyyy):");
this.birthday_yyyy= sc.nextInt();
System.out.printf("출생월을 입력해 주세요.(mm):");
this.birthday_mm= sc.nextInt();
System.out.printf("출생일을 입력해 주세요.(dd):");
this.birthday_dd= sc.nextInt();
System.out.printf("성별을 입력해 주세요.(m/f):");
char sex= sc.next().charAt(0);
if (sex == 'm'){
this.sex= true;
}else if (sex == 'f'){
this.sex= false;
}
}
}
private static int generate6RandomNumbers() {
Random random= new Random();
return random.nextInt(999999);
}
public static void main(String[] args) {
System.out.println("[주민등록번호 계산]");
MyNumber myNumber= new MyNumber();
System.out.println(String.format("%d%d%d-%d%d"
,myNumber.birthday_yyyy
,myNumber.birthday_mm
,myNumber.birthday_dd
,myNumber.sex ? 1 : 2
,generate6RandomNumbers()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment