Complete the class Problem 1, the program does the following: Prompt the user to enter an integer n.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question
Collapse
Problem #1
Complete the class Problem1, the program does the
following:
• Prompt the user to enter an integer n.
• The
program
should find and print the sum of all digits of
the integer n.
for example, if n 341, the program should print 8 because
3 + 4 + 1 = 8.
va
If n = 10374 the program should print 15 because 1 + 0 +
3 +7 + 4 = 15
• Also, if n = -10374, the program still prints the same value
as if n = 10374, think of a way to get the positive value of a
number all the time. Which method always returns the
positive value of any number?
Here are four sample outputs, your output should look
exactly the same as follows:
Enter integer n: 24
The sum of all digits of 24 is: 6
Enter integer n: 1305
ok Air
Transcribed Image Text:Collapse Problem #1 Complete the class Problem1, the program does the following: • Prompt the user to enter an integer n. • The program should find and print the sum of all digits of the integer n. for example, if n 341, the program should print 8 because 3 + 4 + 1 = 8. va If n = 10374 the program should print 15 because 1 + 0 + 3 +7 + 4 = 15 • Also, if n = -10374, the program still prints the same value as if n = 10374, think of a way to get the positive value of a number all the time. Which method always returns the positive value of any number? Here are four sample outputs, your output should look exactly the same as follows: Enter integer n: 24 The sum of all digits of 24 is: 6 Enter integer n: 1305 ok Air
Problem1.java
Problem #1
import java.util.Scanner;
public class Problem1
k #3
Collapse
3 v
4
public static void main (String[] args)
{
Problem #1
6
« #3 (master)
7.
as ir n = 103/4, think Or a way to get the positive
8
number all the time. Which method always returm
9.
ork 3
positive value of any number?
10
E.md
11
12
Here are four sample outputs, your output should
13
exactly the same as follows:
Enter integer n: 24
The sum of all digits of 24 is: 6
0% (1:0)
Java
Terminal
Enter integer n: 1305
codio@cable-fresh:~/workspace$ |
The sum of all digits of 1305 is: 9
Enter integer n: -24
The sum of all digits of -24 is: 6
Enter integer n: 10374
The sum of all digits of 10374 is: 15
TRY IT
Problem1 Test
MacBook Air
Transcribed Image Text:Problem1.java Problem #1 import java.util.Scanner; public class Problem1 k #3 Collapse 3 v 4 public static void main (String[] args) { Problem #1 6 « #3 (master) 7. as ir n = 103/4, think Or a way to get the positive 8 number all the time. Which method always returm 9. ork 3 positive value of any number? 10 E.md 11 12 Here are four sample outputs, your output should 13 exactly the same as follows: Enter integer n: 24 The sum of all digits of 24 is: 6 0% (1:0) Java Terminal Enter integer n: 1305 codio@cable-fresh:~/workspace$ | The sum of all digits of 1305 is: 9 Enter integer n: -24 The sum of all digits of -24 is: 6 Enter integer n: 10374 The sum of all digits of 10374 is: 15 TRY IT Problem1 Test MacBook Air
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr