Question

In: Computer Science

All Hail Modulus Agustus! The modulus operator is used all the time. Realize that if you...

All Hail Modulus Agustus! The modulus operator is used all the time. Realize that if you “mod” any number by a number “n”, you’ll get back a number between 0 and n-1. For example, “modding” any number by 20 will always give you a number between 0-19. Your job is to design (pseudocode) and implement (source code) a program to sum the total of all digits in an input integer number between 0 and 1000, inclusive. Notice that you need to extract individual digits from the input number using the remainder (modulus) and division mathematical operators. For example, if the input number is 123, the sum of its digits is 6. Document your code and properly label the input prompts and the outputs as shown below. PLEASE DO IN JAVA

Solutions

Expert Solution

import java.util.Scanner;

public class SumOfDigits {
   public static void main(String[] args) {
       int input;
       Scanner sc = new Scanner(System.in);
       // reading input from the user
       System.out.println("Enter number between 0-1000");
       input = sc.nextInt();
       int sum = 0;
       int temp=input;
       while (input > 0) {
           // extracting the last digit
           int reminder = input % 10;
           // adding to sum
           sum = reminder + sum;
           // removing the last digit
           input = input / 10;
       }
       // printing the sum details
       System.out.println("Sum of digits in " + temp + " is : " + sum);
       sc.close();
   }
}


Related Solutions

IN C++ LANGUAGE PLEASE::::: All Hail Modulus Agustu!  The modulus operator is used all the time.  Realize that...
IN C++ LANGUAGE PLEASE::::: All Hail Modulus Agustu!  The modulus operator is used all the time.  Realize that if you “mod” any number by a number “n”, you’ll get back a number between 0 and n-1.  For example, “modding” any number by 20 will always give you a number between 0-19.  Your job is to design (pseudocode) and implement (source code)a program to sum the total of all digits in an input integer number between 0 and 1000, inclusive. Notice that you need to...
PLEASE DO THIS IN C#.All Hail Modulus Agustus! The modulus operator is used all the time....
PLEASE DO THIS IN C#.All Hail Modulus Agustus! The modulus operator is used all the time. Realize that if you “mod” any number by a number “n”, you’ll get back a number between 0 and n-1. For example, “modding” any number by 20 will always give you a number between 0-19. Your job is to design (pseudocode) and implement (source code) a program to sum the total of all digits in an input integer number between 0 and 1000, inclusive....
As you realize corporations issue long-term debt in the form of bonds all the time. In...
As you realize corporations issue long-term debt in the form of bonds all the time. In Chapter Three we are told that there are different characteristics of these bonds that affect their yields. Given the following bond listing for Ford Motor Credit Company, list and explain the debt characteristics (Credit (default) risk, Liquidity, Tax Status, Term to maturity, Call feature, Conversion feature) as they relate to this bond and if they are adding or subtracting from the yield on this...
Whether you realize it or not, increased tariffs and the potential for an all out trade...
Whether you realize it or not, increased tariffs and the potential for an all out trade war with China has a big impact on all of us. What are your thoughts on this issue? Keep in mind, this is macroeconomics not political science.
With all those self-driving taxis scooting around, it would be nice if you could hail one...
With all those self-driving taxis scooting around, it would be nice if you could hail one just by giving the usual hand signal as it approaches -- rather than having to use a cell phone to make the pick-up request. You would like to build a system using a camera and quite a lot of image processing computation to recognize when a human is hailing. The currently best processor you can buy isn't fast enough to do this computation before...
Angst is a term used to describe feelings people may have when they realize they are...
Angst is a term used to describe feelings people may have when they realize they are alone, and neurotic anxiety is a mechanism used to avoid these realizations. Give an example of angst and describe the neurotic anxiety that would be exhibited (that you would expect to see.) Discuss why you would expect a person to behave in this manner based on humanistic views.
Firms that operate internationally are able to do all of the following EXCEPT: A. realize location...
Firms that operate internationally are able to do all of the following EXCEPT: A. realize location economies. B. benefit from producing more standardized products and services. C. realize greater cost economies from experience effects. D. earn a greater return by leveraging any valuable skills developed in foreign operations and transferring them to other entities. 1 points    QUESTION 39 All of the following are disadvantages of exporting EXCEPT? A. Itmay help a firm achieve experience curve economies B. High transportation...
Consider the following independent situations: 1. You are the auditor of Hail Pty Ltd a medium...
Consider the following independent situations: 1. You are the auditor of Hail Pty Ltd a medium sized furniture manufacturer. Your audit firm has finalised the financial statements after the client has substantially prepared the accounting records. However, the client admits to having limited knowledge of identifying and calculating impairment and has asked for your assistance. You have proposed a number of adjustments to account for the impairment of assets. 2. You are the auditor of Travel Time Ltd, a large...
You are moving into a new apartment and realize you need a rug to cover the...
You are moving into a new apartment and realize you need a rug to cover the floor. You know a great local store that sells rugs of any dimension you want. They charge a fixed rate per square foot. (a.) Your new place needs a 12 ft by 18 ft rug. You notice that these sides are 50% longer than the rug from your old place. What were the dimensions of the old rug? (b.) You know that a 4...
You are the treasurer for a company and realize that you will require additional operating funds...
You are the treasurer for a company and realize that you will require additional operating funds in three months for three months. Answer the following questions: You are at risk to changes in interest rate. Describe how movements in interest rates might affect your company given this need. There are many ways to mitigate your exposure to the above risk. Discuss two and the pros/cons of each. You should answer these questions in a couple of short paragraphs.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT