728x90
문제
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.
코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int y = Integer.parseInt(br.readLine());
int m = Integer.parseInt(br.readLine());
System.out.println(m+m-y);
}
}
728x90
728x90
'Algorithm > Baekjoon' 카테고리의 다른 글
Baekjoon 14681 사분면 고르기 JAVA (0) | 2022.01.15 |
---|---|
Baekjoon 10773 제로 JAVA (0) | 2022.01.14 |
Baekjoon 1436 영화감독 숌 JAVA (0) | 2022.01.14 |
Baekjoon 1929 소수 구하기 JAVA (0) | 2022.01.14 |
Baekjoon 10828 스택 JAVA (0) | 2022.01.14 |
댓글