2024/05 3

[프로그래머스] [PCCE 기출문제] 2번 / 출력 (java)

문제 풀이 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int c = sc.nextInt(); //풀이 1 int b_square = (int) (Math.pow(c, 2) - Math.pow(a, 2)); //풀이 2 //int b_square = (c - a) * (c + a); System.out.println(b_square); } 해설Math.pow() 메소드는 입력값과 출력값은 모두 double형이며 Math.pow(대상숫자,지수)를 넣어주면 된다

[Spring]@RequiredArgsConstructor

@RequiredArgsConstructor란? Lombok 라이브러리에서 제공하는 기능으로, 클래스의 생성자를 자동으로 생성해주는 어노테이션이다. 일반적으로 Spring에서는 @Autowired를 이용하여 의존성을 주입할 때, 해당 클래스의 생성자를 이용한다.이때 @RequiredArgsConstructor를 사용하면 Lombok이 컴파일 시간에 해당 클래스의 생성자를 자동으로 생성해준다. 따라서, @Autowired와 @RequiredArgsConstructor는 모두 Spring에서 의존성 주입을 처리하는데 사용되지만, @RequiredArgsConstructor를 사용하면 코드가 더 간결해지고, 더 안전하게 의존성을 주입이 가능하다.  예시@Controller@RequestMapping("/bas..

[Spring] @Autowired란?

@Autowired란?Spring에서 @Autowired는 의존성 주입(Dependency Injection)을 간편하게 수행할 수 있도록 도와주는 어노테이션이다. 의존성 주입은 객체 지향 프로그래밍에 있어서 중요한 개념으로, 클래스간의 의존 관계를 외부에서 설정하고, 이를 통해 느슨한 결합(Loose Coupling)을 유지하는 것을 목적으로 한다. (즉, 코드의 유연성과 재사용성을 높일 수 있다.) 사용 예시@Controller@RequestMapping("/basic/items")public class BasicItemController { private ItemRepository itemRepository; @Autowired //생성자가 1개일 경우 @Autowired 생략 가능 ..