함수 fill()


1 C++[ | ]

#include <iostream>
using namespace std;
int main() {
    int A[5] = {1, 2, 3, 4, 5};
    fill(A, A+5, 100);
    for(int i=0; i<5; i++) cout << A[i] << ' '; // 100 100 100 100 100 
}


2 Java[ | ]

import java.util.Arrays;
public class MyClass {
    public static void main(String args[]) {
        int arr[] = new int[] {1, 2, 3, 4, 5};
        Arrays.fill(arr, 100);
        System.out.println( Arrays.toString(arr) ); // [100, 100, 100, 100, 100]
    }
}

3 PHP[ | ]

print_r( array_fill(0,3,100) );
print_r( array_fill(0, 3, 'cat') );
print_r( array_fill(5, 3, 100) );

4 Python[ | ]

print( [100] * 5 ) # [100, 100, 100, 100, 100]
print( ['cat'] * 3 ) # ['cat', 'cat', 'cat']
print( ["cat"] * 3 ) # ['cat', 'cat', 'cat']

5 Ruby[ | ]

arr = Array.new(5, 100)
print arr # [100, 100, 100, 100, 100]
arr = Array.new(3,"cat")
print arr # ["cat", "cat", "cat"]

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}