과거⚰️
배열문제 답없음
아무루
2020. 10. 17. 13:30
package ex;
public class Ex014답없음 {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
int[]temp1 = new int[5];
int[]temp2 = new int[5];
int[]temp3 = new int[5];
// 문제 1) arr의 값을 temp1에 복사 후 출력
// 정답 1) 10, 20, 30, 40, 50
// 문제 2) arr의 값의 2배를 temp2에 복사 후 출력
// 정답 2) 20, 40, 60, 80, 100
// 문제 3) arr의 값에 i를 더한 값을 temp3에 복사 후 출력
// 정답 3) 10, 21, 32, 43, 54
for(int i=0; i<5; i++) {
if(arr[i]>temp1[i]) {
temp1[i]=arr[i];
}
System.out.print(temp1[i]+" ");
}
System.out.println();
for(int i=0; i<5; i++) {
temp2[i]=arr[i]*2;
System.out.print(temp2[i]+" ");
}
System.out.println();
for(int i=0; i<5; i++) {
temp3[i]=arr[i]+i;
System.out.print(temp3[i]+" ");
}
}
}