분류 전체보기
-
2739 구구단PS/백준 2022. 3. 1. 11:10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int num = Integer.parseInt(buf.readLine()); for (int i = 1; i
-
item 14 Comparable을 구현할지 고려하라책/이펙티브 자바 2022. 2. 28. 22:08
Item 14. Comparable을 구현할지 고려하라 Comparable 인터페이스의 compareTo는 두가지만 제외하면 equals와 같다 compareTo는 단순 동치성 비교에 더해 순서까지 비교 가능하며 제네릭하다 Comparable을 구현한 객체들의 배열은 손쉽게 정렬이 가능하다 Comparable을 구현 했다는것은 해당 클래스의 인스턴스에게 자연적인 순서가 존재 한다는 것 검색, 극단값 계산, 자동 정렬되는 컬렉션 관리도 쉽게 가능 알파벳 숫자 연대 같이 순서가 명확한 값 클래스를 작성한다면 반드시 Comparable을 구현하자 compareTo 메서드의 일반 규약은 equals의 규약과 비슷하다 이 객체와 주어진 객체의 순서를 비교한다 이 객체가 주어진 객체보다 작으면 음의 정수를, 같으면..
-
2742 기찍 NPS/백준 2022. 2. 28. 21:38
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); for (int i = loopLeng; 1
-
2741 N 찍기PS/백준 2022. 2. 27. 23:23
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); for (int i = 1; i
-
11721 열 개씩 끊어 출력하기PS/백준 2022. 2. 26. 23:50
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); String inputStr = buf.readLine(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < inputStr.length(); i++) { if(i % 10 == 0 && i != 0) { sb..
-
-
11720 숫자의 합PS/백준 2022. 2. 25. 23:32
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int loopLeng = Integer.parseInt(buf.readLine()); String inputStr = buf.readLine(); int sumTotal = 0; for (int ..
-
11719 그대로 출력하기 2PS/백준 2022. 2. 24. 21:11
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String str = ""; while((str = buf.readLine()) != null){ sb.append(str); sb.append("\n"); } System.out.println(..
-
item 12 toString을 항상 재정의하라책/이펙티브 자바 2022. 2. 24. 21:05
ITEM 12 toString을 항상 재정의하라 Object의 기본 toString 메서드는 우리가 작성한 클래스에 적합한 문자열을 반환하는 경우는 거의 없다 단순히 클래스_이름@16진수로_표시한_해시코드를 반환한다 toString의 일반 규약 간결하면서 사람이 읽기 쉬운 형태의 유익한 정보를 반환해야 한다 모든 하위 클래스에서 이 메서드를 재정의하라 toString 메서드를 잘 구현한 클래스는 디버깅이 용이하다 toString 메서드가 호출되는 경우 객체를 println, printf, 문자열 연결 연산자(+), assert 구문에 넘길때 디버거가 객체를 출력할때 즉 직접 호출하지 않아도 어딘가는 쓰인다 toString 메서드는 해당 객체의 주요 정보를 모두 반환하는게 좋다 map 객체를 출력한다고 가..
-
11718 그대로 출력하기PS/백준 2022. 2. 23. 20:22
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String str = ""; while((str = buf.readLine()) != null){ sb.append(str); sb.append("\n"); } System.out.println(..