목록Algorithm/programmers (27)
midnightly
📃 문제 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요. 📝 풀이 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr1[0].length]; for (int i = 0; i < arr1.length; i++) { for (int j = 0; j < arr1[i].length; j++) { answer[i][j] = arr1[i][j] + arr2[i][j]; } } return answer; ..
📃 문제 함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다. 다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요. 📝 풀이 class Solution { public long[] solution(int x, int n) { long[] answer = new long[n]; answer[0] = x; for (long i = 1 ; i < n; i++) { answer[(int)i] = x * (i + 1); } return answer; } } https://programmers.co.kr/learn/courses/30/lessons/12954 코딩테스트 연습 - x만큼 간격이 있는 n개의 숫자..
📃 문제 이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다. 별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요. 📝 풀이 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); for (int i = 0 ; i < b; i++) { for (int j = 0; j < a; j++) { System.out.print("*"); } System.out.println(""); } } } https://prog..