- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0048.java
More file actions
Latest commit
53 lines (44 loc) · 1.19 KB
/
Copy pathHackerrankJava0048.java
File metadata and controls
53 lines (44 loc) · 1.19 KB
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
43
44
45
46
47
48
49
50
51
52
53
importjava.util.ArrayList;
importjava.util.Scanner;
publicclassHackerrankJava0048 {
publicstaticvoidmain(String[] args) {
// Java Instanceof keyword
// https://www.hackerrank.com/challenges/java-instanceof-keyword/problem?isFullScreen=true
ArrayListmylist = newArrayList();
Scannersc = newScanner(System.in);
intt = sc.nextInt();
for (inti = 0; i < t; i++) {
Strings = sc.next();
if (s.equals("Student"))
mylist.add(newStudent());
if (s.equals("Rockstar"))
mylist.add(newRockstar());
if (s.equals("Hacker"))
mylist.add(newHacker());
}
System.out.println(count(mylist));
}
staticStringcount(ArrayListmylist) {
inta = 0, b = 0, c = 0;
for (inti = 0; i < mylist.size(); i++) {
Objectelement = mylist.get(i);
// --- You need to update this line ---
if (elementinstanceofStudent)
a++;
// --- You need to update this line ---
if (elementinstanceofRockstar)
b++;
// --- You need to update this line ---
if (elementinstanceofHacker)
c++;
}
Stringret = Integer.toString(a) + " " + Integer.toString(b) + " " + Integer.toString(c);
returnret;
}
}
classStudent {
}
classRockstar {
}
classHacker {
}