Concept explainers
The variable x starts with the value 0.
The variable y starts with the value 5.
Add 1 to x.
Add 1 to y.
Add x and y, and store the result in y.
Display the value in y on the screen.
The value of y will be displayed on the screen as “7”.
Explanation of Solution
Analyzing the given English statement:
The program is to add the two values. Initially declare and initialize with the value to the variables. Then, increment both the variables by 1. Addition operation is performed, finally display the output.
The step by step operations are as follows:
Step1: the “x” variable stores the value of 0.
x = 0
Step2: the “y” variable stores the value of 5.
y = 5
Step3: the variable “x” is incremented by 1.
x = x + 1
x = 0 + 1
x = 1
Step4: the variable “y” is incremented by 1.
y = y + 1
y = 5 + 1
y = 6
Step5: add the value of “x” and “y” and store the result in “y”.
y = x + y
y = 1 + 6
y = 7
Step6: display the output.
The value of “y” is 7
The output for the given statement:
The value of y is 7.
Want to see more full solutions like this?
Chapter 1 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Absolute Java (6th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
C Programming Language
Starting Out with Python (4th Edition)
- Q5:- Write program to calculate the equation sin(x) y(x) = x * where x = 0. 1,0. 2,0.3,0.4arrow_forwardDetermine the value of the following arithmetic expression. floor(5.8)arrow_forwardDirection : Make a guessing game program that will generate a random number and ask the user to guess the generated value with at most three (3) attempts: Problem/Required : The system should have the corresponding feature/s: Generate a random value between 1 to 10. Give the user at most 3 attempts to input a value between 1 to 10. Display “Higher” or “Lower” depending on the user’s input compared to the generated value. Display “Sorry, 3 attempts already.” after 3 incorrect attempts, “Congratulations! You got it in n attempt/s” Show the generated number.arrow_forward
- Directions: Use variables to rewrite the following statements formally. 1. The sum of two numbers equals the square of 4. 2. Variable y varies directly as the square of x. 3. Double it and add 3 gives the same result as you square it. 4. It is greater than 2, then it's square is greater than 4.arrow_forward1. Kilometer Converter Write a program that asks the user to enter a distance in kilometers, then converts distance to miles. The conversion formula is as follows: Miles = Kilometers X 0.6214 %3Darrow_forwardQ3a) Summary Newton’s law states that the force, F, between two bodies of masses M1 and M2 is given by: in which k is the gravitational constant and d is the distance between the bodies. The value of k is approximately 6.67 X 10-8 dyn. cm²/g² . Instructions Write a program that prompts the user to input: The masses of the bodies The distance between the bodies. The program then outputs: The force between the bodies. Your program should be able to work with decimals. Q3b) Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would like to know if she gained or lost on a particular investment. Instructions Write a program that allows Cindy to input: The purchase price of each share The selling price of each share The number of shares sold The program outputs: The total amount invested The total amount received from selling The total service…arrow_forward
- (Physics) Coulomb’s Law states that the force, F, acting between two electrically charged spheres is given by this formula: F=kq1q2r2 q1isthechargeonthefirstsphere.q2isthechargeonthesecondsphere.risthedistancebetweenthecentersofthetwospheres.kisaproportionalityconstant. Write an assignment statement to calculate the force, F.arrow_forwardpthyon: Write a program to allow the user to enter five numbers, one at a time. After each entry, tell the user whether the number is odd or even. At the end of all the entries, display the sum total of all the entered numbers on the screen.arrow_forwardFix the codearrow_forward
- *Using IF Statements* 1. Conduct a quiz that contains 4 questions. Each question has 4 possible answers. Ask a user to choose the correct answer for each question. If the user choose the correct answer, add 1 point. Display the total points user earned at the end of the quiz. 2. Ask a user to enter 4 integers and display the largest integer the user entered.arrow_forwardPhytonarrow_forwardto accept the radius of a circle and display its area , where Area=arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning