-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day_21_Solution.java
42 lines (36 loc) · 1.21 KB
/
Day_21_Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Title : Day_21_Solution.java
* Author : Tridib Samanta
* Created : 17-01-2020
* Link : https://www.hackerrank.com/challenges/30-generics/problem
**/
import java.util.*;
class Printer <T> {
public void printArray(T[] array) {
for (T item : array) {
System.out.println(item);
}
}
}
public class Day_21_Solution {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Integer[] intArray = new Integer[n];
for (int i = 0; i < n; i++) {
intArray[i] = scanner.nextInt();
}
n = scanner.nextInt();
String[] stringArray = new String[n];
for (int i = 0; i < n; i++) {
stringArray[i] = scanner.next();
}
Printer<Integer> intPrinter = new Printer<Integer>();
Printer<String> stringPrinter = new Printer<String>();
intPrinter.printArray( intArray );
stringPrinter.printArray( stringArray );
if(Printer.class.getDeclaredMethods().length > 1){
System.out.println("The Printer class should only have 1 method named printArray.");
}
}
}