Posts

Showing posts from January, 2016

Hackerrank : Day 12: Inheritance!

Image
Problem Statement Welcome to Day 12! Check out  this video  reviewing inheritance, or just jump right into the problem. You are given two classes,  Student  and  Grade , where  Student  is the base class and  Grade  is the derived class. Completed code for  Student  and stub code for  Grade  are provided for you in the editor. Note that  Grade  inherits all the properties of  Student . Complete the  Grade  class by writing a class constructor ( Grade(String,String,int,int) ) and a  char calculate()  method. The  calculate  method should return the  character representative of a Student's *Grade.  Score  as defined in this chart: Input Format Input is already handled for you by the code pre-filled in the editor. There are  4  lines of input containing  f i r s t   n a m e ,  l a s t   n a m e ,  p h o n e , and  s c o r e , respectively. Constraints   4 ≤ | f i r s t   n a m e | , | l a s t   n a m e | ≤ 10   phone  contains exactly  7  digits  1 ≤ s c o r e ≤ 1

HackerRank : Day 10: Binary Numbers!

Problem Statement For this challenge, convert a given number,   n , from decimal (base  10 ) to binary (base  2 ). Input Format The first line contains a single integer,  T , the number of test cases. The  T  subsequent lines of test cases each contain a single value,  n , the base  10  positive integer to be converted. Constraints   1 ≤ T ≤ 1000   1 ≤ n ≤ 2 31 Output Format For each test case, print the value of  n  in binary on a new line. Sample Input 2 4 5 Sample Output 100 101 Explanation Test Case 0:   n = 4  evaluates to  1 × 2 2 + 0 × 2 1 + 0 × 2 0 = 1 × 4 + 0 + 0 = 100 .  Test Case 1:   n = 5  evaluates to  1 × 2 2 + 0 × 2 1 + 1 × 2 0 = 1 × 4 + 0 + 1 × 1 = 101 . public class Solution {     public static void main(String[] args) {         /* Enter your code here.*/         Scanner in=new Scanner(System.in);         int T= in.nextInt();         for(int i=1;i<=T;i++)             {            int n = in.nextInt();