백준 6749 자바
Next in line
문제
You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.
Given the ages of the youngest and middle children, what is the age of the oldest child?
입력
The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 ≤ Y ≤ 50). The second line is the age M of the middle child (Y ≤ M ≤ 50).
출력
The output will be the age of the oldest child.
예제 입력 1
12
15
예제 출력 1
18
시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율
1 초 | 128 MB | 5595 | 4860 | 4665 | 87.180% |
나이터울이 다 같으니 그거에 맞게 맏이 나이를 구해달라 는 뜻이다.
코드
import java.util.Scanner;
public class B6749 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int youngest = sc.nextInt();
int middle = sc.nextInt();
sc.close();
System.out.println(middle + (middle - youngest));
}
}
'알고리즘 공부 > 백준 문제풀이' 카테고리의 다른 글
[백준] 15680 : 연세대학교(JAVA) (0) | 2022.10.05 |
---|---|
[백준] 11943 : 파일 옮기기(JAVA) (0) | 2022.10.05 |
[백준] 5575 타임 카드(JAVA) (2) | 2022.10.05 |
[백준]5596 시험점수(JAVA) (0) | 2022.10.05 |
[백준]2338 긴자리 계산(JAVA) (0) | 2022.10.05 |