Suppose we attend a party. To be sociable, we will shake hands with everyone else. Write a fragment of code using a for statement that will compute the total number of handshakes that occur. (Hint: Upon arrival, each person shakes hands with everyone that is already there. Use the loop to find the total number of handshakes as each person arrives.)

What will be an ideal response?

```
int numberAttending = 8;
int handShakes = 0;
for( int person=1; person <= numberAttending; person++){
handShakes += (person - 1);
// When person k arrives, they will
//shake hands with the k-1 people already there
}
System.out.println("The sum is " + sum);
```

This code is in Fragments.java.

Computer Science & Information Technology

You might also like to view...

The Calculator program window includes the Maximize button and scroll bars

Indicate whether the statement is true or false

Computer Science & Information Technology

A new server has two drives and a RAID controller. Which of the following is an option for configuring the storage on this server?

A. RAID 0 B. RAID 5 C. RAID 6 D. RAID 10

Computer Science & Information Technology