Dev/Java

    [Java] 자바 숫자에 천단위 콤마 (,) 표기 (feat. ChatGPT)

    [Java] 자바 숫자에 천단위 콤마 (,) 표기 (feat. ChatGPT)

    import java.text.DecimalFormat; public class Example { public static void main(String[] args) { int number = 1000000; DecimalFormat decimalFormat = new DecimalFormat("#,###"); String formattedNumber = decimalFormat.format(number); System.out.println(formattedNumber); } } Java에서 천 단위로 숫자를 표기하는 방법은 DecimalFormat 클래스를 이용하는 것입니다. DecimalFormat 클래스는 숫자를 포맷팅하는 데 사용되며, 문자열 형식으로 표시할 수 있습니다. 아래는 천 단위 표기를..

    [Java] 해당 월의 마지막 주 값 구하기

    별 내용은 아니지만 개발자 게시판에 질문이 있길래 답변 드릴겸 코딩해봤습니다. 내용은 자바(Java)로 해당 월의 마지막 주 구하기입니다. 코드는 아래와 같습니다. Calendar calendar = Calendar.getInstance(); System.out.println("현재 주 : "+calendar.get(Calendar.WEEK_OF_MONTH));// calendar 현재 주를 구한다. System.out.println("마지막 날 : "+calendar.getActualMaximum(Calendar.DATE));// 마지막 날을 구한다. calendar.set(Calendar.YEAR, Calendar.MONTH+1, calendar.getActualMaximum(Calendar.DATE..

    [JAVA] 1~10000까지 중 8이 포함된 숫자 갯수를 구하라

    구글입사 시험에 나왔다는 알고리즘이라는 얘기가 있는데 그냥 한 번 코딩해보고 싶었다. 다른 방법들도 많겠지만 퍼퍼먼스에 목숨을 거는 그런 개발자이길 바랬지만 가만히 두지 않는다. 오너나 기획자가 기다려 주지 않는다고 해야할까.. 빨리빨리~ 끄적끄적 그냥 쉽게 구할 수 있는 방법을 생각한게 아래의 소스이다. 구글 관계자님 혹시 이 소스 맘에 들면 입사시켜주세요 ㅎㅎㅎ P. S : 더 괜찮은 로직 가지고 계신분은 꼭 아래 댓글 달아주세요 ^^아~ 궁금해 궁금해~ int count = 0; for(int i=1; i=0 ){ System.out.println(String.format("num -> %d", i)); count++; } } System.out.println(String.format("count ..

    자바언어로 이메일 체크하기

    자바(Java)언어로 이메일 체크를 자주 사용할 것 같아서 메서드로 만들어 보았다 /** * 이메일 체크 * @param email 이메일 주소 * @return */ public static boolean isCheckEmailCorrect(String email) { if(email.length() == 0) { return false; } String pttn = "^\\D.+@.+\\.[a-z]+"; Pattern p = Pattern.compile(pttn); Matcher m = p.matcher(email); if(m.matches()) { return true; } return false; } 끝.