Maximum number of handshakes
Java program for finding Maximum number of handshakes
The given program will find the maximum number of handshakes in a room. Suppose there are N persons in a room. We have to find the maximum number of Handshakes possible. Given the fact that any two persons shake hand only once.
A shakes hand with B and C. now B shakes hand with C.Thus total number of ways to shake hands are 2+1 = 3 ways .
Suppose you entered into a room and there are N numbers of people .You shake hand with your friend so now you have N-1 people left to shake hands with . Similarly for your friend there are N-2 people left and so on.
Thus the above problem can be solved by simple nC2 .
- user is asked to input an integer value n, representing the number of people
- calculate answer as n * (n – 1) / 2 as explained earlier .
thus 3 ways.
Print the output from the above program
Code in Java: