글 작성자: 취업중인 피터팬
728x90

https://www.acmicpc.net/problem/6749

 

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 c

www.acmicpc.net

 

등차수열의 첫 번째 값과 두 번째 값을 알려주고 세 번째 값을 출력하라는 문제입니다.

 

정답

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int y = sc.nextInt();
        int m = sc.nextInt();
        
        System.out.println(m+(m-y));
    }
}