Handshakes Java

PROGRAM TO COUNT THE NUMBER OF HANDSHAKES SUCH  THAT A PERSON SHAKES HANDS ONLY ONCE



import java.io.*;
  
class MAIN 
{
  
// function to find all
// possible handshakes
static int handshake(int n) 
{
    // when n becomes 0 that 
    // means all the persons 
    // have done handshake
    // with other
    if (n == 0
        return 0;
    else
        return (n - 1) + handshake(n - 1); 
}
  
// Driver Code
public static void main (String[] args) 
{
    int n = 9;
    System.out.print(handshake(n));
}
}


OUTPUT
36

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java