Java12 1D1A - One Day One Algorithm 문제 - 약수의 합어떤 수를 입력받아 그 수의 약수를 모두 더한 수 sumDivisor 함수를 완성해 보세요. 예를 들어 12가 입력된다면 12의 약수는 [1, 2, 3, 4, 6, 12]가 되고, 총 합은 28이 되므로 28을 반환해 주면 됩니다. import java.util.ArrayList;import java.util.List; class SumDivisor {public int sumDivisor(int num) {int answer = 0; List arr = new ArrayList(); for (int i = 1; i 2018. 3. 13. 10진수를 2진수로 - 입력값을 진법수에 맞게 출력 입력받은 숫자를 원하는 진법의 수로 변환 * Language : Java int input = 133; // 입력값int number = 2; // 진수int temp = 0;int divide = input; List numberList = new ArrayList(); while (divide != 0) { temp = divide % number; numberList.add(temp); divide = (divide - temp)/number;} List reverseNumberList = new ArrayList();for (int i = numberList.size(); i>0; i--) { reverseNumberList.add(numberList.get(i-1));} 2018. 3. 7. Calendar 클래스 사용 - Non-static method cannot be referenced from a static context Date 클래스를 이용한 getDate(), getYear() 이용하고 싶었습니다. 그러나 IDE 상에서 관련 함수들이 전부 Deprecated 되어있었습니다. 조금 찾아보니, Date 클래스는 모든 국가에 사용하기에 적합하지 않기에 JDK1.1 이후부터는 Calendar 클래스를 제공한다고 문서에 나와있습니다. 그래서 Calendar 를 사용해서 Calendar.get(Calendar.YEAR); 를 했는데 아래와 같이 경고 문구가 나왔습니다.Non-static method cannot be referenced from a static context참고 : https://stackoverflow.com/questions/4922145/non-static-method-cannot-be-referenced.. 2018. 3. 2. 디자인 패턴 - Strategy Pattern 디자인 패턴 - Strategy Pattern Interface 와 구현체들그리고 Interface 를 Delegate 한 ClassDelegate 한 클래스를 사용하는 Main Class 강의 : https://www.inflearn.com/course/%EC%9E%90%EB%B0%94-%EB%94%94%EC%9E%90%EC%9D%B8-%ED%8C%A8%ED%84%B4/ 2018. 1. 2. Java - Random 메소드 사용 Java 유틸에서 Random 함수를 쓸때,특정 범위까지 랜덤구하는 방법을 간단하게 구현해놓았다. //1. nextInt(range) = nextInt(max - min) new Random().nextInt(5); // [0...4] [min = 0, max = 4] new Random().nextInt(6); // [0...5] new Random().nextInt(7); // [0...6] new Random().nextInt(8); // [0...7] new Random().nextInt(9); // [0...8] new Random().nextInt(10); // [0...9] new Random().nextInt(11); // [0...10] 참고 : https://www.mkyong.com/.. 2017. 11. 6. [Java] static 과 final 이해하기 final- 변경불가- 상속불가 이해에 도움이 되는 포스팅 : http://blog.naver.com/PostView.nhn?blogId=kiho0530&logNo=150143859108 final 에 대해서 알아보다가 순간 아래와 같은 생각이 들었다.String a = "abd";final String b = a;이렇게하면 a 를 참조하는게 아닌가라는 생각을 해서 고럼 a 값을 변경하면 final 변수가 변경되는게 아닌가 생각했지만... b 는 a를 참조하는게 아니라 "abc"를 참조하는거라서 그게 아니구나...하고 생각했습니다. static- 메모리에 바로 올라간다- 아무데서나 호출이 가능하다 final 과 static 이해에 도움이 되는 포스팅 : http://ojava.tistory.com/50 .. 2017. 7. 19. 이전 1 2 다음