
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question

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](https://content.bartleby.com/qna-images/question/adfbbbe1-5bcd-414e-acb2-f1850b7b8695/57295206-9533-4784-9de7-5fce18c2069a/trn2wm_thumbnail.jpeg)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images

Knowledge Booster
Similar questions
- Financial Application:• Write a program that computes future investment value at a given interest rate for aspecified number of months and prints the report shown in the sample output. • Given the annual interest rate, the interest amount earned each month is computedusing the formula: Interest earned = investment amount * annual interest rate /1200 (=months * 100) • Write a method, computeFutureValue, which receives the investment amount, annualinterest rate and number of months as parameters and does the following: o Prints the interest amount earned each month and the new value of theinvestment (hint: use a loop). o Returns the total interest amount earned after the number of months specified bythe user. The main method will:o Ask the user for all input needed to call the computeFutureValue method.o Call computeFutureValueo Print the total interest amount earned by the investment at the end of thenumber of months entered by the user. Sample Program runningEnter the investment…arrow_forwardSummary In this lab, you complete a prewritten Python program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is make of oak, add $20.00. No charge is added for pine. Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering. Instructions Make sure the file HouseSign.py is selected and open. You need to assign variables for the following: A variable for the cost of the sign assigned to 0.00 (charge). A variable for the number of characters assigned to 8 (numChars). A variable for the color of the characters assigned to "gold" (color). A variable for the wood type assigned to "oak" (woodType). Write the rest of the program using…arrow_forwardThe rule for implicit type conversion in 'C' is A. int < unsigned < float < double B. unsigned < int < float < double C. int < unsigned < double < float D. unsigned < int < double < floatarrow_forward
- Collapse Problem #2 Complete the class Problem2, the program does the following: • The program prompts the user to enter an integer. • The program continues to prompt the user for more integers as long as the sum of all values entered is between 1 and 50. • If the sum of all values entered is NOT between 1 and 50, Java the program stops taking integers, then display the value of sum. Here are two sample outputs, your output should look exactly the same as follows: Enter an integer: 23 Enter an integer: 1 I Enter an integer: -2 Enter an integer: 19 Enter an integer: -25 Enter an integer: 4 Enter an integer: 9 Enter an integer: -20 Enter an integer: -5 Enter an integer: -12 AK -8 lacBook Airarrow_forward(PLEASE USE BASIC JAVA NOT COMPLEX I AM A BEGINNER THANKS) Canadian phone number has the following format: +1 (604) 295- 8959 Area Code= Three digits starting with 2-9Prefix= Three digits starting with 2-9Subscriber= Any four digits 0-9Write a java program, using loops, that asks the user to enter a phone number then if correct print theArea Code, Prefix, and Subscriber numbers. If not correct, print what is wrong. Sample run:Enter a number or -99 to quit: +1 (604) 277-9999The number is correct with area code: 604, prefix 277, and subscriber 9999Enter a number or -99 to quit: 1 (104) 277-0123Country code doesn’t start with + and area code doesn’t start with a 2-9 number.arrow_forwardA company has 5 stores {1, 2, 3, 4, 5}. The sales for each store is as follows: {200, 300, 400, 500, 600}. The tax rate is 6% Write a java program that: 1) Calculates the sales tax for each store and the total sales tax for the company.arrow_forward
- Understanding ifStatements Summary In this lab, you complete a prewritten Java program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is made of oak, add $20.00. No charge is added for pine. Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering. Instructions 1. Ensure the file named HouseSign.java is open. 2. You need to declare variables for the following, and initialize them where specified: A variable for the cost of the sign initialized to 0.00 (charge). A variable for the number of characters initialized to 8 (numChars). A variable for the color of the characters initialized to "gold" (color). A variable for the…arrow_forwardConvert the following statements into intermediate code: int r=0;for (int i=0; i<10; i++) r=r+i;arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education