Posts

Java Iterator class can help you to iterate through every element in a collection - Hacker Rank Solution.

  Java Iterator class can help you to iterate through every element in a collection. Here is a simple example: import java.util.* ; public class Example { public static void main ( String [] args ){ ArrayList mylist = new ArrayList (); mylist . add ( "Hello" ); mylist . add ( "Java" ); mylist . add ( "4" ); Iterator it = mylist . iterator (); while ( it . hasNext ()){ Object element = it . next (); System . out . println (( String ) element ); } } } In this problem you need to complete a method  func . The method takes an  ArrayList  as input. In that  ArrayList  there is one or more integer numbers, then there is a special string "###", after that there are one or more other strings. A sample  ArrayList  may look like this: element[0]=>42 element[1]=>10 element[2]=>"###" element[3]=>"Hello" eleme...

When a method in a subclass overrides a method in superclass, it is still possible to call the overridden method using super keyword - Hacker Rank Solution.

When a method in a subclass overrides a method in superclass, it is still possible to call the overridden method using   super   keyword. If you write   super.func()   to call the function   func() , it will call the method that was defined in the superclass. You are given a partially completed code in the editor. Modify the code so that the code prints the following text: Hello I am a motorcycle, I am a cycle with an engine. My ancestor is a cycle who is a vehicle with pedals. SOLUTION : - import java.io.*; import java.util.*; class Cycle {     String define_me() {         return "a vehicle with pedals." ;     } } class Motorcycle extends Cycle {     @Override     String define_me() {         return "a cycle with an engine." ;     }     Motorcycle() {         System.out.println( "Hello I am a motorcycle, I am " + define_me());   ...

Query the Name of any student in STUDENTS who scored higher than 75 Marks - Hacker Rank Solution.

Image
Query the   Name   of any student in   STUDENTS   who scored higher than    75  Marks . Order your output by the   last three characters   of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending   ID . Input Format The  STUDENTS  table is described as follows:   The  Name  column only contains uppercase ( A - Z ) and lowercase ( a - z ) letters. Sample Input Sample Output Ashley Julia Belvet Solution : SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY SUBSTR(Name, -3) ASC, ID ASC;

In this problem, you will practice your knowledge on interfaces - Hacker Rank Solution.

  A Java interface can only contain method signatures and fields. The interface can be used to achieve polymorphism. In this problem, you will practice your knowledge on interfaces. You are given an interface  AdvancedArithmetic  which contains a method signature  int divisor_sum(int n) . You need to write a class called MyCalculator which implements the interface. divisorSum  function just takes an integer as input and return the sum of all its divisors. For example divisors of 6 are 1, 2, 3 and 6, so  divisor_sum  should return 12. The value of n will be at most 1000. Read the partially completed code in the editor and complete it. You just need to write the MyCalculator class only.  Your class shouldn't be public. Sample Input 6 Sample Output I implemented: AdvancedArithmetic 12 Explanation Divisors of 6 are 1,2,3 and 6. 1+2+3+6=12. Solution : - import java.io.*; import java.util.*; interface AdvancedArithmatic{     int divisor_su...