for(int i : index)

class Telephone{
    public static void main(String[] args) {
        int[] arr = new int[] { 8, 2, 1, 0, 3 };
        int[] index = new int[] { 2, 0, 3, 2, 4, 0, 1, 3, 2, 3, 3 };
        String tel = "";
        for(int i : index) {
            tel += arr[i];
        }
        System.out.println("telephone number=" + tel);
}
for(int i : index)这里的index是作为一个下标。
for(int i : index)
{tel+=arr[i]; }
相当于
for(i=0;index.length;i++)
{tel+=arr[index[i]]

猜你喜欢

转载自blog.csdn.net/jt18729260336/article/details/78916528