Language_Coder 174 : 584 : 함수2 - 자가진단6

boom.jun.cho·2022년 6월 11일
0

Language_Coder_JUNGOL

목록 보기
170/197

문제

main() 함수 내에는 숫자를 사용하지 말고 즉, #define 을 이용하여 1, 2, 3 세 개의 숫자를 조합하여 가능한 한 모든 합을 출력하는 프로그램을 작성하시오.
출력예와 같이 출력하시오

출력

코드

package com.jungol.algorithm170;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.print();
    }

    private void print() {
      int[] ar = {1, 2, 3};

      for(int i = 1; i <= ar.length; i++) {
          for(int j = 1; j <= ar.length; j++) {
              System.out.println(i + " + " + j + " = " + (i + j));
          }
      }
    }
}
profile
하루하루 최선을

0개의 댓글