Concept explainers
(Another Dangling-else Problem) Based on the dangling-else discussion in Exercise 4.27, modify the following code to produce the output shown. Use proper indentation techniques. You must not make any additional changes other than inserting braces and changing the code’s indentation. We’ve eliminated the indentation from the following code to make the problem more challenging. [Note: It’s possible that no modification is necessary.]
- 1 if (y == 8)
- 2 if (X == 5)
- 3 System.out.println("@@@@@");
- 4 else
- 5 System.out.println("#####");
- 6 System.out.println("$$$$$");
- 7 System.out.println("&&&&&");
1 Assuming that x = 5 and y = 8, the following output is produced:
@@@@@
$$$$$
&&&&&
2 Assuming that x = 5 and y = 8, the following output is produced:
@@@@@
3 Assuming that x = 5 and y = 8, the following output is produced:
@@@@@
&&&&&
4 Assuming that x = 5 and y = 7, the following output is produced. [Note: The last three output statements after the else are all part of a block.]
#####
$$$$$
&&&&&
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java How To Program (Early Objects)
- (Please do not give solution in image format thanku) Using the evaluation semantics of SML, rewrite the following expression into its simplest form. If the expression is syntactically illegal or its evaluation results in an error, then simply write "error" as the result. (fn f => (fn y => f y))(fn x => 1 + 1)arrow_forwardDO NOT USE EXISTING ANSWERS ON CHEGG OR COURSE HERO OR ANY OTHER SERVICES PLEASE! Thanks :) CODE IN PYTHON AND SHOW COMMENTS TO EXPLAIN CODE A confused Dutchman trying to speak English could say “I am in the war”, even though there is no hostile activity going on. The confusion1 here is that the English sentence “I am confused” is translated in Dutch as “Ik ben in de war”, which is phonetically (“sounding”) quite close to the first sentence. Such confusion leads to much enjoyment, but can complicate matters a bit. Given a sentence in Dutch and a dictionary containing both correct translations as well as phonetic (incorrect) translations of individual words, find the translation of the sentence and indicate whether it is correct, or in case there is more than one find the total number of correct and incorrect translations. A sentence is correctly translated when each word of the sentence is correctly translated. Input The input consists of: One line with an integer n (1≤n≤20), the…arrow_forward[Updated[ Python Code Pt1: Algorithms and Data Structures Please use the sample input to see if the code works, as the output of the final code, must be the same as the correct output. Follow the details and notes provided and show the complete working sample code. Additionally, include comments to make the code easier to understand. I will show how the output was found (check K);Note: The final code should result in correct output (check I) if sample input A (check H) is used, or else I will give an automatic thumbs down A. TASKThe user inputs a path system and the work needed to traverse them. The goal is to Identify the relationships between paths, whether they have sequential, adjacent, or null relationships. For every sequential and adjacent relationship, give their work done based on the formula (check D). B. SAMPLE A path system illustration //See Image C. Relationship Examples with Sample A as basisSequential relationships: Path1 and Path2 as they are single paths that are…arrow_forward
- Q2) (Perfect Numbers) An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.arrow_forward(Bar-Chart Printing Program) One interesting application of computers is drawing graphsand bar charts. Write a program that reads five numbers (each between 1 and 30). For each numberread, your program should print a line containing that number of adjacent asterisks. For example,if your program reads the number seven, it should print *******.arrow_forward( (A + B ) * (C – D) + E / F ) – G Using manual and algorithmic methods, write the following expression to postfix form:arrow_forward
- ▼ Part A - The effect of an arithmetic shift on signed numbers Let's look at see what happens to signed numbers during a shift operation. As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine. signed int mult_2_to_n (signed int num, int n) { signed int result; result = num << n; printf("%d multiplied by 2^%d %d\n", num, n, result); return result; } Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below…arrow_forwardContext: Using Python, I am also a beginner in programming. Having a hard time completing this practice and assisstance is appreciatedarrow_forward(Target-Heart-Rate Calculator) While exercising, you can use a heart-rate monitor to see thatyour heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA) (www.americanheart.org/presenter.jhtml?identifier=4736), theformula for calculating your maximum heart rate in beats per minute is 220 minus your age in years.Your target heart rate is a range that is 50–85% of your maximum heart rate. [Note: These formulas areestimates provided by the AHA. Maximum and target heart rates may vary based on the health, fitness andgender of the individual. Always consult a physician or qualified health care professional before beginning ormodifying an exercise program.] Create a class called HeartRates. The class attributes should include theperson’s first name, last name and date of birth (consisting of separate attributes for the month, dayand year of birth). Your class should have a constructor that receives this data as…arrow_forward
- ( MindTap - Cenage )Example 5-6 implements the Number Guessing Game program. If the guessed number is not correct, the program outputs a message indicating whether the guess is low or high. Modify the program as follows: Suppose that the variables num and guess are as declared in Example 5-6 and diff is an int variable. Let diff = the absolute value of (num - guess). If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number. Suppose diff is not 0. Then the program outputs the message as follows: If diff is greater than or equal to 50, the program outputs the message indicating that the guess is very high (if guess is greater than num) or very low (if guess is less than num). If diff is greater than or equal to 30 and less than 50, the program outputs the message indicating that the guess is high (if guess is greater than num) or low (if guess is less than num). If diff is greater than or equal to 15 and less than 30, the…arrow_forward-Python- Learning Objective: Use loops to iterate through the container Practice the enumerate() function to have simultaneous access to index and object Work with If statements to perform action only by specific condition Instructions You are parking in Los Angeles Airport and you can only remember the floor of where you parked your car. A programmer can help you find your car in the parking by only giving him the brand of your car. The program will give you the number of the parking lots that have cars with the same brand as yours. The program works as follows: Input from the user car_brand Loop over the cars in parking_cars list (hint: use enumerate) Save the indices in a list parking_lots of the cars with the same brand as the user's (car_brand) If parking_lots has values, print "Your car might be in any of these parking lots <parking_lots>". Otherwise, print "Sorry, your car is not on this floor." ex. input :Toyota / output: Your car might be in any of these parking lots…arrow_forward[Python (py3)] The error in the code below is if the number of rows of the matrix is not equal to its number of columns, matrix addition will not be performed. This should not be the case since the only requirement for matrices addition is that the dimension of Matrix A is equal to the dimension of Matrix B. Please resolve the error in the code below such that Matrix A and Matrix B can be added if the dimension of Matrix A is equal to the dimension of Matrix B. PLEASE do not just copy the code below and use it as the answer itself. I've encountered such case many times. Please modify the code. When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." The input will come from file1.txt, and the output should only be printed to output.txt Format of the input from file1.txt:First Line: type of operation (add)Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)Third Line: matrix A…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning