Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java dividing one integer by another truncates the remainder, which removes the decimal part. To compute the integer remainder, we use the remainder operator

  • In Java dividing one integer by another truncates the remainder, which removes the decimal part. To compute the integer remainder, we use the remainder operator (%), also known as the modulus operator.
  • The % operator finds the remainder after division of one number by another. The Java expression a % b (pronounced a mod b) returns the remainder of the division of a by b if both numbers are positive. For example:
 3 r 1 2 ) 7 -6 1 remainder
  • For this assignment we will use both the division and remainder operators to extract single digits form an integer number.
  • Write a program that gets three numbers from the user and then sums:
    • the hundreds digit of the first number
    • with the tens digit of the second number and
    • the unit digit of the third number.
  • For example, the sum of the diagonal digits of the following three numbers is 3 because the numbers are all 1 on the diagonal as shown by the highlight.
    123 416 781 
  • Name the source code file SumDiagonal.java and include all your code in this single file.
  • Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
    Enter first number: 123 Enter second number: 416 Enter third number: 781 Sum of diagonal digits is 3 
    Enter first number: 123 Enter second number: 456 Enter third number: 789 Sum of diagonal digits is 15 
    Enter first number: 1234 Enter second number: 56 Enter third number: 789 Sum of diagonal digits is 16 
    Enter first number: 1 Enter second number: 2 Enter third number: 3 Sum of diagonal digits is 3 
    In the above example output, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics.

    Notice the fourth example. Entering a 1 is the same as 001. Similarly, entering a 2 is the same as entering 002 and entering a 3 is the same as entering 003. Thus arranging the three numbers in a matrix of rows and columns shows us how the answer was derived.

    001 002 003 
  • Ask the user for the three integer numbers, and no other input, as shown in the Example Run.
  • Use the division operator (/) and remainder operator (%) to extract digits from the numbers entered by the user.
  • Example Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and same wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
  • After displaying the output, exit the program.
  • Do not use if-statements, strings or techniques we have not covered.
  • Submit SumDiagonal.java to Canvas when your program works as shown.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions