Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Generic Grading Guidelines a. Please make sure youre only using the concepts already discussed in class. That is, please try and restrict yourself to loops,

Generic Grading Guidelines a. Please make sure youre only using the concepts already discussed in class. That is, please try and restrict yourself to loops, selection statements, String methods that talked on class, arrays, and your own written methods. b. The programs are worth 35 points, 35 points, 30 points. c. You do not need to perform any form of input type checks. d. Please make sure that youre conforming to specifications (program name, print statements, expected inputs and outputs etc.). e. Please make sure your code is readable. f. Please make sure youve compiled and run your program before you turn it in. -5 pts will be deducted for each compile error.

1. GCDandLCM.java 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 ii. GCD is smaller or equal to both a and b, larger or equal to 1 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. e. Print out the two result. 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

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

Students also viewed these Databases questions