• + 0 comments

    import java.util.*;

    public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int t = sc.nextInt();
    
            // Peek the next token to check if it is an int
            if (sc.hasNextInt()) {
                Integer[] arr = new Integer[t];
                for (int i = 0; i < t; i++) {
                    if (sc.hasNextInt()) {
                        arr[i] = sc.nextInt();
                    }
                }
                printArray(arr);
            } else {
                String[] arr = new String[t];
                for (int i = 0; i < t; i++) {
                    if (sc.hasNext()) {
                        arr[i] = sc.next();
                    }
                }
                printArray(arr);
            }
        }
    
        sc.close();
    }
    
    public static <T> void printArray(T[] array) {
        for (T item : array) {
            System.out.println(item);
        }
    }
    

    }