[Programmers / Level0] PCCE 기출문제 2번 / 피타고라스의 정리 (Java)

이하얀·2024년 8월 5일
0

🕊️ 프로그래머스

목록 보기
23/43

💡 Info




입출력 조건 및 예시




문제 이해


  • 주어진 코드의 버그를 찾아 수정하는 문제
    • 직각삼각형의 한 변의 길이를 나타내는 정수 a와 빗변의 길이를 나타내는 정수 c가 주어질 때, 다른 한 변의 길이의 제곱, b_square 을 출력하도록 한 줄을 수정해 코드 완성


알고리즘 & 최종 풀이


  • 문제

  • 수정 전 코드
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int c = sc.nextInt();

        int b_square = c - a;

        System.out.println(b_square);
    }
}
  • 수정 후 코드
    • 풀이 시간 : 3분
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int c = sc.nextInt();

        int b_square = c*c - a*a; // C^2 - a^2으로 수정

        System.out.println(b_square);
    }
}


결과

profile
언젠가 내 코드로 세상에 기여할 수 있도록, BE 개발 기록 노트☘️

0개의 댓글