In this HackerRank Java Instanceof keyword problem, we need to add some lines of the code that are missing, and you have to fix it by modifying only 3 lines! Don't add, delete or modify any extra line.

HackerRank Java Instanceof keyword problem solution

HackerRank Java Instanceof keyword problem solution

import java.util.*;

class Student{}
class Rockstar{   }
class Hacker{}

public class InstanceOFTutorial
   static String count(ArrayList mylist)
      int a=0,b=0,c=0;
      for(int i=0;i<mylist.size();i++)
         Object element=mylist.get(i);
         if(element instanceof Student)
         if(element instanceof Rockstar)
         if(element instanceof Hacker)
      String ret= Integer.toString(a)+" "+ Integer.toString(b)+" "+ Integer.toString(c);
      return ret;

   public static void main(String []argh)
      ArrayList mylist=new ArrayList();
      Scanner sc=new Scanner(;
      int t=sc.nextInt();
      for(int i=0;i<t;i++)
         if(s.equals("Student"))mylist.add(new Student());
         if(s.equals("Rockstar"))mylist.add(new Rockstar());
         if(s.equals("Hacker"))mylist.add(new Hacker());