Java(50)
-
[Java] double, float을 println으로 찍게 되면
값이 작으면 그대로 출력이 되지만값이 커지면 지수표기법이 사용된다.예를 들어, 다음과 같다.39999999999.5 => 3.99999999995E10이를 지수표기법을 사용하지 않고 찍고 싶다면 다음의 경우들로 가능하다.아래 경우 모두 다 마지막 자리에 맞춰 반올림을 해준다.1. System.out.printfSystem.out.println("printf");System.out.printf("%.1f%n", area);2. DecimalFormatimport java.text.DecimalFormat;System.out.println("DecimalFormat");DecimalFormat df = new DecimalFormat("#.#");System.out.println(df.format(area)..
2025.01.22 -
[Java] int의 범위
-21억 ~ 21억
2024.04.08 -
[Java] RuntimeException 정리
IllegalArgumentException: 메서드가 잘못된 인자를 넘겨받았을 때 발생합니다. IndexOutOfBoundsException: 배열, 벡터의 범위에 벗어나는 인덱스에 접근할 때 발생합니다. NullPointerException: 객체가 요구되는 상황에서 애플리케이션이 null 값을 사용하려고 할 때 발생합니다. ArithmeticException: 예외적 산술 조건이 생겼을때 발생합니다. 예를 들어, 0으로 나눌때 발생합니다. UserInterruptException: 사용자 인터럽트 제어가 가능하고 사용자가 ctrl-C와 같은 인터럽트 문자를 눌렀을 때 발생합니다. UncheckedIOException: IOException을 unchecked exception으로 랩핑합니다. Ill..
2024.02.05 -
[Java] static 변수 사용시 주의사항
static 변수를 만들고 메서드에서 같은 이름의 지역 변수를 만들고 초기화하면 static 변수는 여전히 초기화되지 않는다. 예를 들어, 아래와 같이 설정을 해놓았다. public class SubSet { static int N, target; static int[] subSet; static int[] set; static boolean isSelected[]; public static void main(String[] args) { set = new int[] {1, 2, 3}; int N = set.length; subSet = new int[N]; isSelected = new boolean[N]; generateSubSet(0); } 그리고 아래의 함수를 사용하면 원하는 결과가 나오지 않는다..
2024.02.01 -
[Java] this와 super의 차이에 대한 나름의 이해
this는 객체를 뜻하는 것으로 upcasting된 객체일 수도 있고 이게 쓰인 클래스의 객체일 수도 있다. super는 부모를 뜻한다. 엄밀히 말하면 조상이다.
2024.02.01 -
[Java] 스트림 특히 read(byte b[], int offset, int len)에 대한 이해
스트림은 단방향으로만 통신이 가능 입력과 출력의 끝단: 노드 두 노드를 연결하고 데이터를 전송할 수 있는 개념: 스트림 public int read(byte b[], int offset, int len): 최대 len 만큼 데이터를 읽어서 b의 offset 부터 b에 저장하고 읽은 바이트 개수를 리턴한다. 따라서 len+offset은 b의 크기 이하여야 한다. offset은 b[]의 offset이다. b[offset]부터 b[offset+len-1] 까지 저장한다는 뜻이다. binary data = stream 문자열 = er buffer를 두는 이유는 IO 작업이 비싸기 때문 Reference https://docs.oracle.com/javase/8/docs/api/ Java Platform SE 8..
2024.01.29