3. Write segments of code for the following. a. Write an if statement to determine whether...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. Write segments of code for the following. a. Write an if statement to determine whether an integer j is even or odd. (2 marks) b. Use a switch statement to rewrite the following if statement: (4 marks) if (a == 1) x += 5; else if (a == 2) x += 10; else if (a == 3) x += 16; if (a == 4) x += 34; c. Convert the following for loop statement to (i) while loop and (ii) do-while loop. (4 marks) long sum = 0; for (int i = 0; i <= 2000; i+=2) sum= sum + i; 3. Write segments of code for the following. a. Write an if statement to determine whether an integer j is even or odd. (2 marks) b. Use a switch statement to rewrite the following if statement: (4 marks) if (a == 1) x += 5; else if (a == 2) x += 10; else if (a == 3) x += 16; if (a == 4) x += 34; c. Convert the following for loop statement to (i) while loop and (ii) do-while loop. (4 marks) long sum = 0; for (int i = 0; i <= 2000; i+=2) sum= sum + i;
Expert Answer:
Answer rating: 100% (QA)
Here are the code segments a If statement to determine even or odd jav... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Consider the hydrogen atom, and assume that the proton, instead of being a point- source of the Coulomb field, is uniformly charged sphere of radius R ( < < ao), so that the Coulomb potential is now...
-
Two boxes sit side-by-side on a smooth horizontal surface. The lighter box has a mass of 5.2 kg; the heavier box has a mass of 7.4 kg. (a) Find the contact force between these boxes when a horizontal...
-
The focus of a SOC 1 report is on: a. Cybersecurity. b. The integrity of transaction processing c. Internal controls over financial reporting d. Determining if there is a significant deficiency or a...
-
Petitioner Atlantic Marine Company was a contractor located in Virginia. It entered into a subcontract with J-Crew Management, Inc., a Texas corporation, that contained a forum-selection clause...
-
Waters Hardware Store completed the following merchandising transactions in the month of May. At the beginning of May, Waters ledger showed Cash of $8,000 and Common Stock of $8,000. May 1 Purchased...
-
ESG CSR Study caseSunset Manufacturing Inc. manufactures Umbrellas in the Western Canadian market, and is comparing the budget for the current year with the actual results. The market has been good...
-
Most businesses sell several products at varying prices. The products often have different unit variable costs. Thus, the total profit and the breakeven point depend on the proportions in which the...
-
Respond to the following question: What is it about using a BlackBerry (or another brand of personal digital assistant) that so managers believe increases their productivity?
-
- A block of mass m = 6, 1 kg slides on a rough surface and moves toward a spring with a spring constant k = 1932 N/m, as shown in the figure below. When the block is d 25, 2 m away from the spring,...
-
Would you rather have an excellent benefits package or higher pay? Explain.
-
To what extent is it Human Resources' responsibility in creating safety, inclusion, awareness and equal treatment of LGBTQ employees? Please present arguments in support of your position.
-
3D wave speeds have been calculated using ultrasonic transducers. The estimated values are V = 6200 m/sec, vs = 3200 m/sec. Assuming the material density as p=2700 kg/m, compute: a) Young Modulus E...
-
TIPS and FOE are instrumental to employers in thwarting the success of a union organizing campaign. Define each acronym and explain why they are important to management in labor relations practices.
-
A recent survey showed that among 775 randomly selected subjects who completed 4 years of college, 162 smoke and 613 do not smoke. Determine a 95% confidence interval for the true proportion of the...
-
An investor sells a European call on a share for $4. The stock price is $47 and the strike price is $50. Under what circumstances does the investor make a profit? Under what circumstances will the...
-
Steve Drake sells a rental house on January 1, 2012, and receives $130,000 cash and a note for $55,000 at 10 percent interest. The purchaser also assumes the mortgage on the property of $45,000....
-
Bev and Ken Hair have been married for 3 years. They live at 3567 River Street, Springfield, MO 63126. Ken is a full-time student at Southwest Missouri State University (SMSU) and Bev works as an...
-
Charlie's Green Lawn Care is a cash basis taxpayer. Charlie Adame, the sole proprietor, is considering delaying some of his December 2012 customer billings for lawn care into the next year. In...
-
This chapter suggests that estimating project costs is a challenging process that can resemble an art form as much as science. Describe the different methods used to estimate costs on a project. How...
-
Consider the common problems with project cost estimation and recall a project with which you have been involved. Which of these common problems did you encounter most often? Why?
-
Explain the concept of activity-based costing. What are the steps involved in this process?
Study smarter with the SolutionInn App