public class Test {
public static void main(String[] args) {
int arr[] = {1,2,3,4};
int i=0;
while (i<20)
{
System.out.println(arr[?]);
}
}}
우리는 무엇을 대신 써야합니까? 그래서 ArrayIndexOutOfBounds
예외가 발생하지 않고 출력은 다음과 같습니다.매우 혼란스러운 자바 코드를 도와주세요.
System.out.println(arr[i%4]);
하지만 난을 증가하는 것을 잊지 마세요 : 그것은 당신에게 당신의 배열의 인덱스는 0과 3 사이의 정수를 줄 것이기 때문에
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
xxxxxxxxxxx –