Skip to content

Instantly share code, notes, and snippets.

@Starlight258
Last active January 15, 2024 08:02
Show Gist options
  • Save Starlight258/d8f7f17c9a920867cdcfd1148fcb3692 to your computer and use it in GitHub Desktop.
Save Starlight258/d8f7f17c9a920867cdcfd1148fcb3692 to your computer and use it in GitHub Desktop.
0114_과제4
// 김명지
import java.util.Random;
import java.util.Scanner;
public class a4 {
public static void main(String[] args) {
// 입력받기
System.out.println("[주민등록번호 계산]");
Scanner sc = new Scanner(System.in);
System.out.print("출생년도를 입력해 주세요.(yyyy):");
int birthYear = sc.nextInt();
System.out.print("출생월을 입력해 주세요.(mm):");
int month = sc.nextInt();
System.out.print("출생일을 입력해 주세요.(dd):");
int day = sc.nextInt();
System.out.print("성별을 입력해 주세요.(m/f):");
boolean isMan = sc.next().equals("m");
// 주민등록번호 생성
String registerNum = "" + birthYear % 100;
registerNum += month < 10 ? "0" + month : month;
registerNum += day < 10 ? "0" + day : day;
registerNum += "-";
registerNum += isMan ? "3" : "4";
Random random = new Random();
registerNum += random.nextInt(999999) + 1;
System.out.println(registerNum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment