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_forward5. (Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 X 2 system of linear equation: ax + by = e cx + dy = f ● x = ed - bf bc ad y = af - ec ad bc - Write a program that prompts the user to enter a, b, c, d, e, and f and display the result. If ad- bc is 0, report that The equation has no solution. Enter a, b, c, d, e, f: 9.0, 4.0, 3.0, -5.0, -6.0, -21.0 Enter x is -2.0 and y is 3.0 Enter a, b, c, d, e, f: 1.0, 2.0, 2.0, 4.0, 4.0, 5.0 Enter The equation has no solutionarrow_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
- 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_forward4. (Looping statement) java Given an integer, display its reversed order. Sample Output: Enter n : 876 The reversed order of 876 is 678.arrow_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
- (the use of .length and the importance of string) *please explain the use of .length in this statement, and the importance of string in our overall code* if (studentNumber.length() > 10) //2019104921 I goto loop; else if(studentNumber.length() < 10) goto loop;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(Q1)This is a Data Structures problem and the programming language used is Lisp. Solve the question we detailed steps and make it concise and easy to understand. Please and thank you.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning