Handshakes Java
PROGRAM TO COUNT THE NUMBER OF HANDSHAKES SUCH THAT A PERSON SHAKES HANDS ONLY ONCE
OUTPUT
36
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)); } }
36
Comments
Post a Comment