You are viewing a single comment's thread. Return to all 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); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 21: Generics
You are viewing a single comment's thread. Return to all comments →