class SumMatrix { int[][] sumMatrix(int[][] A, int[][] B) { int[][] answer = new int[A.length][A[0].length]; for(int i=0;i<A.length;i++) { for(int j=0;j<A[0].length;j++) { answer[i][j] = A[i][j]+B[i][j]; } } return answer; } // 아래는 테스트로 출력해 보기 위한 코드입니다. public static void main(String[] args) { SumMatrix c = new SumMatrix(); int[][] A = { { 1, 2 }, { 2, 3 } }; int[][] B = { { 3, 4 }, { 5, 6 } }; int[][] answer = c.sumMatrix(A, B); if (answer[0][0] == 4 && answer[0][1] == 6 && answer[1][0] == 7 && answer[1][1] == 9) { System.out.println("맞았습니다. 제출을 눌러 보세요"); } else { System.out.println("틀렸습니다. 수정하는게 좋겠어요"); } } }
public class Caesar { String caesar ( String s , int n ) { n %= 26 ; String result = "" ; char [] temp = s . toCharArray (); for ( int i = 0 ; i < temp . length ; i ++) { if ( temp [ i ]>= 'a' && temp [ i ]<= 'z' ) temp [ i ] = ( char ) (( temp [ i ]+ n )> 'z' ? ( temp [ i ]+ n - 1 )% 'z' + 'a' : ( temp [ i ]+ n )); else if ( temp [ i ]>= 'A' && temp [ i ]<= 'Z' ) temp [ i ] = ( char ) (( temp [ i ]+ n )> 'Z' ? ( temp [ i ]+ n - 1 )% 'Z' + 'A' : ( temp [ i ]+ n )); result += temp [ i ]; } return result ; } public static void main ( String [] args ) { Caesar c = new Caesar (); System . out . println ( "s는 'a B z', n은 4인 경우: " + c . caesar ( ...
댓글
댓글 쓰기