Friday, 27 May 2016

Hackarank Binary Number - Java Solution

WOW! I solved the second puzzle after 1.5 days of RnD and hard work! Trying all the logic's thinking and patience always pays off!

From yestrday I wn working on this puzzle, may be for some of you it is not that much tricky but for me it was.

Feeling so happy after completing the puzzle at last.


Learn Share n Grow!



Objective
Today, we're working with binary numbers. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given a base- integer, , convert it to binary (base-). Then find and print the base- integer denoting the maximum number of consecutive 's in 's binary representation.
Input Format
A single integer, .
Constraints
Output Format
Print a single base- integer denoting the maximum number of consecutive 's in the binary representation of .
Sample Input 1
5
Sample Output 1
1
Sample Input 2
13
Sample Output 2
2
Solution 1:

package com.number;

import java.util.Scanner;

public class BinaryV2 {
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int rem=0,s=0,t=0;


    while(n>0)
        {
        rem=n%2;
        n=n/2;
        if(rem==1)
         {   s++;
           if(s>=t)

     

Thursday, 26 May 2016

Hackarank 2D Array GlassHour Problem - Java Solution


Hello Coders,
I am posting this code for my future reference.
Below is the problem statement!

Task
Calculate the hourglass sum for every hourglass in , then print the maximum hourglass sum.
Input Format
There are  lines of input, where each line contains  space-separated integers describing 2D Array ; every value in will be in the inclusive range of  to .
Constraints
Output Format
Print the largest (maximum) hourglass sum found in .
Sample Input
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0
Sample Output
19


Solution: 



import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;



public class Solution {



    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int a[][] = new int[6][6];

      

Tuesday, 17 May 2016

Aspect Oriented Programming or Object Oriented Programming : Still Confused ?




While learning Spring from JavaTpoint, I just come up with a topic named AOP ! First, I thought it some feature which comes up with Spring, when I started diving in,after couple of minutes literally speaking my head start spinning around and all the concepts where jumping off my head.

So I thought, first I will try to learn what actually this AOP means. After doing some googling and reading on wiki, I come to know that it is more of a Programming Para-diagram just like Object Oriented Programming a.k.a OOPs.

Going in more detail the best answer I found in stack overflow..

I am copy pasting that answer for my future reference.

Read it you will come to know what actually AOP is and how to use it!


Blog Top Sites

Share Our Badge

 Computer Stuffs

Be Updated Its Free.

Subscribe via Email

Visitors Everyday



Website Security Test

Followers