In: Computer Science
JAVA for Dummies HELP
Problem Statement: Jeff Bezos has decided to have a party at his mansion, and he’s invited 50 couples. As the couples arrive at the mansion, they receive a ticket with a number (like at the deli counter), with the first couple receiving the tickets labeled 1 and 2, the second couple getting 3 and 4, and so on. Jeff has noticed in the past that when he throws parties, conversation groups most often occur in groups of 4 people. Being a nerd, he wonders: Exactly how many different conversation groups of 4 are possible at this party?
He writes himself a short Java program, and in minutes he has his answer….
(WRITE THIS PROGRAM)
(An important small hint – the person who has the ticket with a “1” on it can only (obviously) occur once in a given group – so, for example the grouping 1, 1, 2, 3 could NEVER occur!)
initialize a counter to 0;
--for each possible int value for personOne (starting at 1, ending at 100-3)
-----for each possible int value for personTwo (starting at personOne+1, ending at 100-2)
-------for each possible int value for personThree(starting at personTwo+1, ending at 100-1)
--------for each possible int value for personFour(staring at personThree+1, ending at 100)
increment the count output the result;
public class Groups {
public static void main(String[] args) {
int numGroups = 0;
for(int p1 = 1; p1 <= 100-3;
p1++) {
for(int p2 = p1
+ 1; p2 <= 100 - 2; p2++)
for(int p3 = p2 + 1; p3 <= 100-1; p3++)
for(int p4 = p3 + 1; p4 <=
100; p4++)
numGroups++;
}
System.out.println("The number of
different groups of 4 that can be formed is " + numGroups);
}
}
output
-------
The number of different groups of 4 that can be formed is
3921225