Write a program to calculate the greatest common divisor and lowest common multiplier of two integers...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program to calculate the greatest common divisor and lowest common multiplier of two integers given by user. Suppose the two input integers are a and b, the Greatest Common Divisor GCM is defined as the largest integer that satisfies a % GCM == 0 && b% GCM == 0. And the Lowest Common Multipler LCM is defined as the smallest integer that satisfies LCM%a == 0 && LCM%b == 0. a. Some properties of GCD and LCM that may help you build your loops: i. LCM is larger or equal to both a and b, and smaller or equal to a*b GCD is smaller or equal to both a and b, larger or equal to 1 ii. iii. LCM and GCD are related. You can based on one to calculate the other one. b. Import Scanner class to receive the two integers from user. c. Declare two integers to store the GCD and LCM. d. Build a loop to check if certain number is GCD. If yes, terminate the loop with the GCD recorded. Calculate the LCM similarly. Print out the two result. e. Sample Run 1: Please input 2 integers: 100 125 The GCD is 25 The LCM is 500 Sample Run 2: Please input 2 integers: 24 48 The GCD is 24 The LCM is 48 Sample Run 3: Please input 2 integers: 70 70 The GCD is 70 The LCM is 70 Write a program to calculate the greatest common divisor and lowest common multiplier of two integers given by user. Suppose the two input integers are a and b, the Greatest Common Divisor GCM is defined as the largest integer that satisfies a % GCM == 0 && b% GCM == 0. And the Lowest Common Multipler LCM is defined as the smallest integer that satisfies LCM%a == 0 && LCM%b == 0. a. Some properties of GCD and LCM that may help you build your loops: i. LCM is larger or equal to both a and b, and smaller or equal to a*b GCD is smaller or equal to both a and b, larger or equal to 1 ii. iii. LCM and GCD are related. You can based on one to calculate the other one. b. Import Scanner class to receive the two integers from user. c. Declare two integers to store the GCD and LCM. d. Build a loop to check if certain number is GCD. If yes, terminate the loop with the GCD recorded. Calculate the LCM similarly. Print out the two result. e. Sample Run 1: Please input 2 integers: 100 125 The GCD is 25 The LCM is 500 Sample Run 2: Please input 2 integers: 24 48 The GCD is 24 The LCM is 48 Sample Run 3: Please input 2 integers: 70 70 The GCD is 70 The LCM is 70
Expert Answer:
Answer rating: 100% (QA)
Provided below the implementation of GCDandLCM class as per the given requirement GCDandLCMjava impo... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
A college offers tutoring in Math, English, Chemistry, and Biology. The number of students enrolled in each subject is listed below. If the college can only afford to hire 14 tutors, determine how...
-
1) Sleep More Corporation has pledged to pay a $10 per share dividend every year indefinitely. if you require an 11% return on your investment, how much will you pay for the company's shares today? ...
-
Melissa is a sole trader. Her capital gains and capital losses for 2020-21 are 27,000 and 700 respectively. She has capital losses brought forward from 2019-20 of 12,900 and she also has unrelieved...
-
The shareholders' equity section of Superior Corporation's balance sheet as of December 31, 2012, is as follows Required: 1. Prepare journal entries for each of the above transactions. 2. Calculate...
-
Sally received a demand loan of $17,500 on December 02, 2018 at 18% p.a. simple interest. She made a small repayment of $200 on December 31, 2018 towards the loan, and a larger repayment of $5000 on...
-
What is the free-rider problem? Why does it discourage innovation in environmental protection and the adoption of high environmental standards? Can anything be done to overcome the free-rider problem?
-
Demand for rug- cleaning machines at Clyde's U- Rent- It is shown in the following table. Machines are rented by the day only. Profit on the rug cleaners is $ 10 per day. Clyde has four rug-cleaning...
-
The analyzing of organizations in the lens of this theory features the use of asking questions in order to gage the health of the organization. One of the questions often asked with the use of this...
-
Use Microsoft Visio or Visible Analyst to view and print the contextlevel data flow diagram for the computer inventory system as Chip and Anna did E2 Use the Repository feature or the Repository web...
-
Following is the receipt and payment account of friends recreational club for the year ended 31st dec. 2018. Prepare Income and expenditure account: Receipts Balance b/d Annual subscription Annual...
-
2. What is the average salary offered to a Stony Brook college graduate? To study this question you and a friend interview N students that graduated last year, and ask them what they earn. Student...
-
Considering the Code 5 in Kundu et al., for solution of one-dimensional compressible Euler Equations, add the capabilities to the code for obtaining: a) The plots shown in Fig. 6-26 plus the...
-
Write a MIPS assembly language program that generates a sequence of integers, such that each integer in the sequence is the sum of the last three integers. For example, if the sequence starts with 0,...
-
4. (25 points) Suppose you want to estimate the model: Yi = Bo+ BiXi+Ui where X, is an endogenous variable and all our setup assumptions for instrumental variables hold. Assume Z, is a binary...
-
Warren died and left his nephew, Samuel, a plot of vacant land. Warren purchased the land for $50,000 about 15 years ago. The FMV as of the date of death was $72,500 and the FMV six months later was...
-
1. What are the service management characteristics of the CSR job? 2. Define the mission statement and strategy of the Help Desk. Why is the Help Desk important? Who are its customers? 3. How would...
-
Select a mass spectrometric technique with the highest mass resolution for identifying an unknown compound being eluted from a liquid chromatography column
-
Find the first ten square numbers that are greater than Long.MAX_VALUE. A square number is a number in the form of n2. For example, 4, 9, and 16 are square numbers. Find an efficient approach to run...
-
Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule. Create the...
-
Write a program that prompts the user to enter the number of students and each students name and score, and finally displays the student with the highest score and the student with the second-highest...
-
Using the fourth-order Runge-Kutta method, solve Problem 11.15. Data From Problem 11.15:- Using the second-order Runge-Kutta method, solve the differential equation \(\ddot{x}+1000 x=0\) with the...
-
Using the central difference method, find the response of the two-degree-of-freedom system shown in Fig. 11.2 when \(c=2, F_{1}(t)=0, F_{2}(t)=10\). Figure 11.2:- X1(t) -x2(t) F(1) k=2 -F2(t) k = 4...
-
Using the central difference method, find the response of the system shown in Fig. 11.2 when \(F_{1}(t)=10 \sin 5 t\) and \(F_{2}(t)=0\). Figure 11.2:- X1(t) -x2(t) F(1) k=2 -F2(t) k = 4 k2=6 00000...
Study smarter with the SolutionInn App