본문 바로가기

728x90

Java/잡동사니

(3)
십이지신 계산하기 /* * 십이지신을 통틀어 영어로 Chinese Zodiac이라고 한다. * 직역하면 "중국식 황도십이궁"인데 십이지신의 기원이 중국이고 * 서양 점성술의 기본이되는 황도십이궁(조디악)과 비슷한데서 유래됨 */ public class ChineseZodiac { // 십간(十干) 데이터 final static String[] gan ={"갑", "을", "병", "정", "무", "기", "경", "신", "임", "계"}; final static String[] hgan = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; // 십이지(十二支) 데이터 final static String[] ji = {"자", "축", "인", "묘", "진", "사", "오"..
절대 경로 알아내기 package kr.top2blue.MavenProject; import java.io.File; import java.io.IOException; public class GetPathEx { public static void main(String[] args) { System.out.println("-".repeat(80)); System.out.println(System.getProperty("user.dir")); System.out.println("-".repeat(80)); File f = new File("."); System.out.println(f.getAbsolutePath()); try { System.out.println(f.getCanonicalPath()); } catch (IOE..
1줄 자바 Lotto import java.util.Random; public class Lotto { public static void main(String[] args) { new Random().ints(1, 46).distinct().limit(6).sorted().forEach((e) -> { System.out.printf("%3d", e); }); } } new Random() // 난수 생성기 .ints(1, 46) // 1 ~ 45 사이의 난수 생성(intStream 생성) .distinct() // 중복제거 .limit(6) // 6개만 .sorted() // 정렬 .forEach((e) -> { // 최종연산 : 람다식을 이용한 출력 System.out.printf("%3d", e); // 3칸에 맞추어 ..

728x90