본문 바로가기

Algorithm/백준

[백준] 5522: 카드 게임 - JAVA [자바]

 


 

문제


 

  1. 다섯 개의 수를 입력합니다.
  2. 입력된 수의 총합을 출력합니다.

 

문제 풀이


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int result = 0;
        for (int i = 0; i < 5; i++) {
            int score = sc.nextInt();
            result += score;
            //(1)
        }

        System.out.println(result);
        //(2)
    }
}

 

  1. 5번 반복하여 수를 입력하고, 그 수를 result 변수에 더해줍니다.
  2. result를 출력합니다.

 

결과