Sort by

recency

|

360 Discussions

|

  • + 0 comments

    TypeScript

    function printArray<T>(array: T[]): void {
        for (let i = 0; i < array.length; i++) {
            console.log(array[i]);
        }
    }
    
    function main() {
    
        let n: number = parseInt(readLine().trim(), 10);
    
        const intArray: number[] = new Array(n);
        for (let i = 0; i < n; i++) {
            intArray[i] = parseInt(readLine().trim(), 10);
        }
    
        n = parseInt(readLine().trim(), 10);
    
        const stringArray: string[] = new Array(n);
        for (let i = 0; i < n; i++) {
            stringArray[i] = readLine().trim();
        }
    
        printArray<number>(intArray);
        printArray<string>(stringArray);
    }
    
  • + 0 comments

    //javaScript

    function printArray(array) { for (const element of array) { console.log(element); } }

  • + 0 comments
    c# csharp
    
    static void PrintArray<T>(T[] value)
        {
      //Linq ArrayForEach
            Array.ForEach(value, rec => Console.WriteLine($"{rec}"));
      //or Normal ForEach, both is working in similar way
      // foreach(var rec in value)
      //Console.WriteLine($"{rec}"); 
          }
    
  • + 0 comments
    template <typename T>
    void printArray(const vector<T>& vec) {
        for (const T& element : vec) {
            cout << element << endl;
        }
    }
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    import java.util.regex.*;;
    
    public class Solution {
    
        public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          while(sc.hasNext()) {
            int t = Integer.parseInt(sc.next());
            if(sc.hasNext(Pattern.compile("[0-9]+"))) {
              Integer[] ints = new Integer[t];
              for (int i = 0; i < t; i++) {
                ints[i] = sc.nextInt();
              }
              printArray(ints);
            } else {
              String[] strs = new String[t];
              for (int i = 0; i < t; i++) {
                strs[i] = sc.next();
              }
              printArray(strs);
            }
          }
          
          sc.close();
        }
        
        
        public static <T> void printArray(T[] array) {
          for (T t : array) {
            System.out.println(t);
          }
        }
    }