#### Question Details

##### [solution] » Please provide Accurate answers to the questions using examples

**Brief item decscription**

Step-by-step solution file

**Item details:**

Please provide Accurate answers to the questions using examples**More:**

**Please provide Accurate answers to the questions using examples where necessary**

**1.The gcd() function, de ned in a class Euclid, takes two nonnegative integer arguments and return the greatest common divisor of the two integers.**

** **

**public class Euclid {**

** **

**public static int gcd(int p, int q) { if (q == 0) return p;**

** **

**return gcd(q, p % q);**

** **

**}**

** **

**}**

** **

** **

** **

**a. Write an overloaded function gcd() that takes three non negative integer arguments and return the greatest common divisor of the three integers. Assume that the function is in the same class Euclid as the two-argument version above.**

** **

**Hint: Use the identity gcd (p; q; r) = gcd(gcd( p; q); r). For example, gcd(504; 4116; 4410) = gcd(gcd(504; 4116); 4410) = gcd(84; 4410) = 42.**

** **

** **

**b. Give the signature of a function that takes as an argument an array of non negative integers and returns the greatest common divisor of those integers. Do not implement the function.**

**2.Consider the following TOY code fragment.**

** **

** **

**20: 2AAB R[A] <- R[A] - R[B]**

** **

**21: DA20if (R[A] > 0) pc <- 20**

** **

**22: CA24if (R[A] == 0) pc <- 24**

** **

**23: 1AAB R[A] <- R[A] + R[B]**

** **

**24: 0000halt**

** **

** **

** **

** **

**i. Suppose that just before the code fragment is executed, R[A] stores the value 001A and R[B] stores the value 0008. What are the values of R[A] and R[B] upon termination?**

** **

** **

**R[A]:**

** **

**R[B]:**

** **

** **

** **

** **

** **

** **

**ii. Suppose that just before the code fragment is executed, R[A] stores the value 5EAB and R[B] stores the value 0010. What are the values of R[A] and R[B] upon termination?**

** **

** **

**R[A]:**

** **

**R[B]:**

** **

** **

** **

** **

** **

** **

**iii. Give a one-line Java statement that corresponds to the TOY code fragment above, assuming that R[A] and R[B] contain positive integers and a and b are the corresponding Java int variables.**

** **

**3. Consider the following Java program.**

** **

** **

**public class Mystery {**

** **

**public static void main(String[] args) { int curr = StdIn.readInt(); StdOut.print(curr + " ");**

** **

**int prev = curr;**

** **

**while (!StdIn.isEmpty()) { curr = StdIn.readInt();**

** **

**StdOut.print((prev + curr) / 2 + " "); prev = curr;**

** **

**}**

** **

**StdOut.println();**

** **

**}**

** **

**}**

** **

** **

**Assume the contents of the input.txt are given below.**

** **

**% more input.txt**

** **

**2 4 6 8 10 12 8 2**

** **

** **

** **

**i. What is the result of the following command? Circle your answer.**

** **

**java Mystery < input.txt**

** **

** **

** **

** **

** **

** **

** **

** **

**ii. What is the result of the following command? Circle your answer.**

** **

**java Mystery < input.txt | java Mystery**

** **

**About this question:****STATUS**

Answered

QUALITY

Approved

ANSWER RATING

Pay using PayPal (No PayPal account Required) or your credit card. All your purchases are securely protected by PayPal.

Answered

QUALITY

Approved

ANSWER RATING

This question was answered on: * Feb 21, 2020 *

* * Solution~000492207.zip (18.37 KB)

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy (Deadline assured. Flexible pricing. TurnItIn Report provided)

### Need a similar solution fast, written anew from scratch? Place your own custom order

We have top-notch tutors who can help you with your essay at a reasonable cost and then you can simply use that essay as a template to build your own arguments. This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student. New solution orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.