Posts

Showing posts from 2015

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

Cross River puzzle

Two boys want to cross a river. Only one boat is present on the riverside that can carry only one person at a time. However, they still manage to cross the river. How is it possible ?

Count mangoes puzzle

In a basket of Mangoes, when counted in twos, there was one extra when counted in threes, there were two extra when counted in fours, there were three extra when counted in fives, there were four extra when counted in sixes, there were five extra. However, if the mangoes were counted in sevens, no extra mango was left. Can you calculate the minimum number of mangoes that were present in the basket ?

Turn off Whatsapp tone in Windows phone

Image
To turn off whatsapp tone on Windows phones, Please go through following steps: 1. Go to Settings of Windows phone. 2. Go to Notifications and Actions 3. Click on whatsapp 4. Change/disable the tone.  Enable/disable vibrate option for whatsapp.

Place queen on Chessboard puzzle

Image
Can you place 8 queens on the board in a manner that none of the queens can attack each other? Note: Queen moves horizontal, vertical and diagonally. Please see below image for reference.

Tricky Question

On my way to Temple, I saw a man with 7 wives. Each wife had 7 sacks. Each sack had 7 cats. Each cat had 7 kittens. Kitten, cats, sacks, wives, How many livings were going to Temple?

Tricky Question

Circle exact four numbers to get sum of 12.                     1    6     1                     6    1     6                     1    6     1                     6    1     6                     1    6     1                     6    1     6

Suspect in hotel puzzle

An old man was sitting in his hotel room when he heard a knock on the door. he opened the door and found that a man was standing outside.  The man said, "Oh! I am really sorry, I thought this was my room." He then walked through the corridor to the elevator. The old man did not know the man. he closed his door and called the security asking them to arrest the man. What made him suspicious of that man? He might have been genuinely mistaken.

Chessboard Puzzle

Image
Can you count the number of squares in a chess board ? Buy Lawman Slim Fit Men