Concept explainers
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 who is already there. Use the loop to find the total number of handshakes as each person arrives.)
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- The following code examines two variables -- x and y -- and prints the largest odd number among them.  If none of them is odd, it prints a message to that effect. def largestOdd(x,y):  """  x and y are numbers  Returns the maximum odd number of x and y.   If they all are even, return None       """     foundOdd = False  largest = 0  if x % 2 == 1 :    largest = x    foundOdd = True  if y % 2 == 1 :    if not foundOdd :      largest = y      foundOdd = True    elif y > largest :      largest = y  if foundOdd :    return largest  else :    return None   Assume that largestOdd is called with numbers as arguments.Which of the following test suites would make a path-complete glass box test suite for largestOdd?  Question 6 options:  Test Suite A: foundOdd(2,4), foundOdd(2,5), foundOdd(11,12), foundOdd(11,13), foundOdd(11,7)  Test Suite B: foundOdd(2,4), foundOdd(2,6), foundOdd(11,12),…arrow_forwardSuppose n1 and n2 are two int variables that have been given values. Write anif-else statement that outputs "n1" if n1 is greater than or equal to n2, andthat outputs "n2" otherwise.arrow_forwardIn Coral Programing!! Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is 93, the output is: 93 92 91 90 89 88 Ex: If the input is 77, the output is: 77 Ex: If the input is not between 20 and 98 (inclusive), the output is: Input must be 20-98 For coding simplicity, follow each output number by a space, even the last one. Use a while loop. Compare the digits; do not write a large if-else for all possible same-digit numbers (11, 22, 33, ..., 88), as that approach would be cumbersome for large ranges.arrow_forward
- This Code print the first occurrences of x, Please Modify the code to print the last occurrences of x and print how many times it exists? ( with explanation for each line if possible) many thanks.arrow_forwardComplete the function below that takes in three integers (a,b,c) and returns the number of integers between a and b (inclusive of the endpoints) that are divisible by c. Make sure it tests a and b for divisibility by c!  In [ ]: defhow_many_divisible(a,b,c):counter=0# YOUR CODE HEREraiseNotImplementedError()returncounter  In [ ]: assert how_many_divisible(10,20,5) == 3 assert how_many_divisible(30,77,7) == 7  PYTHON jYPYTERarrow_forwardUse C++ Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is either heads or tails. Assume the input is a value greater than 0. Ex: If the input is: 3 the output is: heads tails heads For reproducibility needed for auto-grading, seed the program with a value of 2. In a real program, you would seed with the current time. In that case, every program's output would be different, which is what is desired but can't be auto-graded. Note: A common student mistake is to call srand() before each call to rand(). But seeding should only be done once, at the start of the program, after which rand() can be called any number of times. Your program must define and call the following function that returns "heads" or "tails".string HeadsOrTails()arrow_forward
- What is the value of x after the following code executes? int x=10; if(x++ >10) { x =13; } a. 10                          b.9                             c.13                            d.11arrow_forwardAn oil slick occurs when an underwater refinery pipe ruptures, pumping oil into the water. The spilled oil sits on top of the water and causes a natural disaster. For simplicity, suppose that the oil sits on top of the water in the form of a circle. Write a program that prompts the user to enter the rate at which the ruptured pipe pumps oil (in gallons) per minute, the thickness of the oil on top of the water, and the number of days for which the area is covered by the spilled oil. The program outputs the spilled area (in kilometer) and the volume of oil (in gallons) on top of the water after each day.arrow_forwardYou can find out how many seconds have elapsed since Jan 1, 1970 using the time() function. #include <time.h> now = time(NULL); // now is more than a billion seconds (which data type should you use?) Write a program that estimates how many years, months, weeks, days, and hours have gone by since Jan 1 1970 by calculations with the number of seconds that have passed. The number of months must be less than 12, i.e., take out how many years have gone by first, then how many months are left, then weeks, etc. Assume that all years have 365 days, and all months have 30.42 days. Don’t use a calculator, or any web site that reports the number of seconds in a month, etc. – your C program can calculate anything that you need. Notice that this is an assignment on using arithmetic in C.  Hints. How many seconds are in a minute? hour? A day? A week? A month? A year?arrow_forward
- What will be the value of x after the following code is executed? int x = 0; while (x < 50) {     x += 20; }   50   20   40   60arrow_forwardCreate class name whileloopActivity and write a program to produce the following output using nested while loopsarrow_forwardQ3, A lecturer intends to separate his students into 2 groups based on their INDEX Numbers, those with odd numbers in group A and EVEN numbers in B. Use if-else statement to implement this. Q4.Your son intends to randomly mention some numbers to you, write a program using While or do-whileloop that will print all the numbers and the sum of the positive numbers.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,