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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education