Posts

Half full and Half Empty Glass

You are given a round glass full of water having capacity of 1 Ltr. You do not have any kind of measurements or any other things. How you will remove water from this glass such that glass will contain exact half of its quantity (500ml).

Gold Bar and Worker

You are having a gold bar and you need a worker to finish some work at your home.  Work will be finished in exact 7 days. You need to pay worker every day with equal part of the gold bar.  You are allowed to make two breaks in the Gold bar.  So how you will be going to pay to the worker ? Note: You need to pay equal part of Gold bar everyday.

Children in House Puzzle

Nine children are in a house and only these 9 are in house, no-one else in house other than these 9 children. A is ironing. B is watching TV C is playing Foosball D is listening radio E is bathing F is sleeping G is dressing I is cooking So what is H doing ? For Hint: Click Here Hint will be uploaded in 1 Day.

Red Apple Puzzle

There are 200 apples in basket, out of which 99% apples are Red apple. How many red apples must be removed to make the percentage of Red apple 98% ? For Hint: Click Here To make Red apple 98%, you need to make other apples count as 2. Currently basket have 2 other apples.

Bus Ticket Puzzle

Two deaf and dumb guys Ramesh and Suresh went to bus station. They wanted to take ticket to Kalyan station from thane and ticket cost per person is 50rs. Ramesh gave him 100rs and Ticket master gave him two tickets without looking at him. How did ticket master get to know that he wants two tickets not one as ticket master did not even seen his face ? For Hint: Click Here He did not gave 100rs Note.

Prime Number Program in Java

Prime number is a number which is divisible by itself. We can write this program in multiple ways but it will reduce the performance for  larger numbers. Here we define one of faster and optimised way to check if number is prime or not. public boolean isPrime( int value) {           if(value == 2)                    return true;            if (value % 2 == 0)                    return false ;          for ( int j = 3; j <= Math.sqrt(value); j+=2) {                if (value % j == 0) {                        return false ;               }         }         return true ; } In this function, we first check if number is divisible by 2 or not. If not then no need to check with any other even numbers, So in for loop we increment value by 2. We use sqrt(value) as upper limit as if value is multiple of two number like a and b, then one of this number will be always less than square root value. So by using sqrt as upper limit, we will redu