
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 2, Problem 2.6PE
(Sum the digits in an integer) Write a
Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.
Here is a sample run:
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
LAB
ACTIVITY
21.16.1: LAB*: Program: Rock paper scissors
Exit Full screen
0/10
Program Specifications Write a program to play an automated game of Rock, Paper, Scissors. Two players make one of
three hand signals at the same time. Hand signals represent a rock, a piece of paper, or a pair of scissors. Each combination
results in a win for one of the players. Rock crushes scissors, paper covers rock, and scissors cut paper. A tie occurs if both
players make the same signal. Use a random number generator of 0, 1, or 2 to represent the three signals.
Note: this program is designed for incremental development. Complete each step and submit for grading before starting the
next step. Only a portion of tests pass after each step but confirm progress.
Step 0. Read starter template and do not change the provided code. Integer constants are defined for ROCK, PAPER, and
SCISSORS. A Random object is created and a seed is read from input and passed to the Random object. This supports
automated…
20.22: LAB*: Program: Text message decoder
20.22 LAB*: Program: Text message decoder
LAB
ACTIVITY
20.22.1: LAB*: Program: Text message decoder
Full screen
0/6
☐
Program Specifications Write a program that reads a line of text message and identifies any supported
abbreviations in the text.
Note: This program is designed for incremental development. Complete each step and submit for grading before
starting the next step. Only a portion of tests pass after each step but confirm progress.
Step 1 (3 pts): Read and verify user input.
Use getline() to read a line of user input into a string. Output the string. Submit for grading to confirm 2 tests
pass.
Ex: If the input is:
Enter text:
IDK if I'll go. It's my BFF's birthday.
the output is:
You entered: IDK if I'll go. It's my BFF's birthday.
Step 2 (3 pts): Identify abbreviations.
Search the string (by using find()) for any supported abbreviations and print a list of found abbreviations along
with the decoded meaning. Assume each unique…
The Greatest and Least of These
Write a program with a loop that lets the user enter a series of integers. The user should
enter -99 to signal the end of the series. After all the numbers have been entered, the
program should display the largest and smallest numbers entered.
Input your program in the blank textbox, run it against the web based C++ tool to ensure it compiles
Please make sure to comment your code, this is worth 3 points for this question.
114
Edit View Insert Format Tools Table
1201
Search
F3
F4
F5
A
PrtScn
Hom
F6
F7
F8
Chapter 2 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Ch. 2.2 - Identify and fix the errors in the following code:...Ch. 2.3 - How do you write a statement to let the user enter...Ch. 2.3 - Prob. 2.3.2CPCh. 2.4 - Prob. 2.4.1CPCh. 2.5 - Identify and fix the errors in the following code:...Ch. 2.6 - Identify and fix the errors in the following code:...Ch. 2.7 - Prob. 2.7.1CPCh. 2.8 - Prob. 2.8.1CPCh. 2.8 - Translate the following algorithm into Java code:...Ch. 2.9 - Prob. 2.9.1CP
Ch. 2.9 - Prob. 2.9.2CPCh. 2.9 - Prob. 2.9.3CPCh. 2.9 - Prob. 2.9.4CPCh. 2.9 - Prob. 2.9.5CPCh. 2.9 - Prob. 2.9.6CPCh. 2.9 - Write a statement to display the result of 23.5.Ch. 2.9 - Suppose m and r are integers. Write a Java...Ch. 2.10 - How many accurate digits are stored in a f1oat or...Ch. 2.10 - Prob. 2.10.2CPCh. 2.10 - Prob. 2.10.3CPCh. 2.10 - Which of the following are correct literals?...Ch. 2.11 - How would you write the following arithmetic...Ch. 2.12 - Prob. 2.12.1CPCh. 2.13 - Prob. 2.13.1CPCh. 2.14 - Which of these statements are true? a. Any...Ch. 2.14 - Show the output of the following code: int a = 6;...Ch. 2.15 - Prob. 2.15.1CPCh. 2.15 - Prob. 2.15.2CPCh. 2.15 - Show the following output: float f =12.5F; int i =...Ch. 2.15 - If you change (int) (tax 100) / 100.0 to (int)...Ch. 2.15 - Prob. 2.15.5CPCh. 2.15 - Write an expression that rounds up a double value...Ch. 2.16 - How would you write the following arithmetic...Ch. 2.17 - Show the output of Listing 2.10 with the input...Ch. 2.18 - Can you declare a variable as int and later...Ch. 2.18 - Prob. 2.18.2CPCh. 2.18 - Will overflow cause a runtime error?Ch. 2.18 - Prob. 2.18.4CPCh. 2 - (Convert Celsius to Fahrenheit) Write a program...Ch. 2 - (Compute the volume of a cylinder) Write a program...Ch. 2 - (Convert feet into meters) Write a program that...Ch. 2 - (Convert pounds into kilograms) Write a program...Ch. 2 - (Financial application: calculate tips) Write a...Ch. 2 - (Sum the digits in an integer) Write a program...Ch. 2 - (Find the number of years) Write a program that...Ch. 2 - (Current time) Listing 2.7. ShowCurrentTime.java,...Ch. 2 - (Physics: acceleration) Average acceleration is...Ch. 2 - (Science: calculating energy) Write a program that...Ch. 2 - (Population projection) Rewrite Programming...Ch. 2 - (Physics: finding runway length) Given an...Ch. 2 - (Financial application: compound value) Suppose...Ch. 2 - (Health application: computing BMI) Body Mass...Ch. 2 - (Geometry: distance of two points) Write a program...Ch. 2 - (Geometry: area of a hexagon) Write a program that...Ch. 2 - (Science: wind-chill temperature) How cold is it...Ch. 2 - (Print a table) Write a program that displays the...Ch. 2 - (Geometry: area of a triangle) Write a program...Ch. 2 - (Financial application: calculate interest) If you...Ch. 2 - (Financial application: calculate future...Ch. 2 - (Financial application: monetary units) Rewrite...Ch. 2 - (Cost of driving) Write a program that prompts the...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- KS My library> CS 20.4 LAB: Max of 3 LAB ACTIVITY 20.4.1: LAB: Max of 3 Full screen 0/10 Write a program that takes in three integers as inputs and outputs the largest value. If the input integers are the same, output the integers' value. Ex: If the input is: 1 2 3 the output is: Max of [1, 2, 3] is 3 Run main.cpp #include 1 2 using namespace std; 3 4 int main() { 5 int vall; Q Search Open new tab El Do History Tuarrow_forward21.5: LAB: Countdown until matching digits 21.5 LAB: Countdown until matching digits LAB ACTIVITY 21.5.1: LAB: Countdown until matching digits Full screen 0/10 Write a program that takes in an integer in the range 11-99 (inclusive) as input. The output of the program is a countdown starting from the input integer until an integer where both digits are identical. End with a newline. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 11 the output is: 11 Ex: If the input is: or any value not between 11 and 99 (inclusive), the output is: Input must be 11-99 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,.... 99), as that approach would be cumbersome for larger ranges. Run main.cpp 1 #include 2 using namespace std; 3 4 int main() { 5 6 7 8 / Type your code here. */ return 0; 9 } 10 Open new tab Dock History Tutorial…arrow_forward23.2 LAB: Step counter LAB ACTIVITY 23.2.1: LAB: Step counter Full screen 0/10 A pedometer treats walking 1 step as walking 2.5 feet. Define a function named FeetToSteps that takes a double as a parameter, representing the number of feet walked, and returns the number of steps walked as an integer by type casting. Then, write a main program that reads the number of feet walked as an input, calls function FeetToSteps() with the input as an argument, and outputs the number of steps returned from FeetToSteps(). Use floating-point arithmetic to perform the conversion. Note: Type casting a double to an integer may affect the result's accuracy. Ex: If the input is: 150.5 the output is: 60 The program must define and call a function: int FeetToSteps (double userFeet) Run main.cpp 1 #include 2 #include 3 using namespace std; 4 5 /* Define your function here */ 6 7 int main() { 8 / Type your code here */ 9 10 return 0; 11 12 Open new tab Dock History Tutorial ENG 3:05 PMarrow_forward
- 19.11 LAB: Convert to seconds LAB ACTIVITY 19.11.1: LAB: Convert to seconds LJ Full screen Write a program that reads in seconds, minutes, and hours as input, and outputs the time in seconds only. Ex: If the input is: 40 6 1 where 40 is the number of seconds, 6 is the number of minutes, and 1 is the number of hours, the output is: 4000 seconds ▷ Run main.cpp #include 1 2 using namespace std; 3 4 int main() { 5 int seconds; int minutes Q Search Open new tab History H Warrow_forwardThe Greatest and Least of These Write a program with a loop that lets the user enter a series of integers. The user should enter-99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered. Input your program in the blank textbox, run it against the web based C++ tool to ensure it compiles Please make sure to comment your code, this is worth 3 points for this question. Edit View Insert Format Tools Table 12pt v Paragraph BIUA T² v هم ...arrow_forwardAreas of Rectangles The area of a rectangle is the rectangle's length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same. Input your program in the blank textbox, run it against the web based C++ tool to ensure it compiles Please make sure to comment your code, this is worth 3 points for this question. Edit View Insert Format Tools Table 12pt v Paragraph BIUA T² Varrow_forward
- Miles per Gallon Write a program that calculates a car's gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold and the number of miles it can be driven on a full tank. It should then display the number of miles that may be driven per gallon of gas. Input your program in the blank textbox, run it against the web based C++ tool to ensure it compiles Please make sure to comment your code, this is worth 3 points for this question. Edit View Insert Format Tools Table 12pt v Paragraph BIUAarrow_forwardRead Chapter 1 of Ralph Stair's textbook, "Fundamentals of Information Systems," 9th Edition, and then write a response to the two discussion questions. Your response should be between half and a page long. Describe how you might use information systems in a career area of interest to you. What things might managers in an organization do that could unintentionally discourage innovation by their employees? How can innovation be encouraged?arrow_forwardPython question:arrow_forward
- Payroll Flowchart Analysis Discuss the risks depicted by the following payroll system flowchart. Describe the internal control improvements to the system that are needed to reduce these risks with specific explanations. An illustration of the above flowchart: It is represented in six columns and the column header reads: supervisor; payroll; data processing; accounts payable; cash disbursement; general ledger. In supervisor column, timekeeper enters into time cards and that leads to “Review Time cards and prepares Personnel Action Form” that further leads to two source documents “time cards, per action form.” Per action, form enters into prepare payroll in payroll column. Prepare payroll enters into paychecks and two source documents “payroll register, payroll register.” Payroll register leads to inverted triangle and payroll leads to A. Paycheck enters into review and distribute in supervisor column leads to paycheck and that further leads to employees. In data processing column,…arrow_forwardUsing the following execution shown below, explain what is done in each of the ARIES recovery algorithm phases: LSN LOG 00 begin_checkpoint 10 end_checkpoint 20 update: T1 writes P1 30 update: T2 writes P2 40 update: T3 writes P3 50 T2 commit 60 update: T3 writes P2 70 T2 end 80 update: T1 writes P5 90 T3 abort CRASH, RESTART In addition to the execution shown here, the system crashes during recovery after writing two log records to stable storage and again after writing another two log recordsarrow_forwardA new application is being developed and will be using a database that includes a relation about items: Item (item_id:integer, item_name:string, color:string, price:real). Both the purchasing department in charge of obtaining raw material and the manufacturing department in charge of manufacturing the items can change the price of manufactured items according to changes that may happen in the raw material cost or production cost. The two departments use different transactions to update the price of items. The new application uses the following sequences of actions, listed in the order they are submitted to the DBMS: Sequence S1: T1:R(X), T2:W(X), T2:W(Y), T3:W(Y), T1:W(Y), T1:Commit, T2:Commit, T3:Commit Sequence S2: T1:R(X), T2:W(Y), T2:W(X), T3:W(Y), T1:W(Y), T1:Commit, T2:Commit, T3:Commit For each of the following concurrency control mechanisms, describe how they will handle each of the sequences (S1 & S2). Strict 2PL with timestamps used for deadlock prevention. Conservative…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License