bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6.6, Problem 6.6.1CP

Explanation of Solution

//Class test

public class Test

{

public static void main(String args[])

{

int x= gcd(4,6);

System.out.println(x);

}

public static int gcd(int n1, int n2)

{

//Declare the variable "gcd" to 1

int gcd=1;

//Declare the variable "k" to 1

int k=2;

/*Check the condition that the specified value lies between "n1" and "n2"*/

while (k<=n1 && k<=n2)

{

/*Check the condition for n1 and n2 mod k equals to 0 */

if(n1%k==0 && n2%k==0)

//Assign "gcd" to "k"

gcd=k;

//Increment the "k"

k++;

}

//Return the gcd

return gcd;

}

}

Explanation:

Definition for Main method:

  • Method “gcd()” is called by passing the value (4,6)...

Blurred answer
Students have asked these similar questions
Python - Need help! How do I have an input in turtle to display my name below the circle it draws and another input to display my age written below that? Code: import turtlebackground = "#FFFFFF" def draw_circle(radius, line_color, fill_color):    my_turtle.color(line_color)    my_turtle.fillcolor(fill_color)    my_turtle.begin_fill()    my_turtle.circle(radius)    my_turtle.end_fill() def move_turtle(x, y):    my_turtle.penup()    my_turtle.goto(x, y)    my_turtle.pendown()   turtle.done()
Need help fixing my python code! Images attached on the required modficications I dont know how to do. Simpler the better.Code: (in images)
Answer all of the questions with steps by step explanation to every question.

Chapter 6 Solutions

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Binary Numbers and Base Systems as Fast as Possible; Author: Techquikie;https://www.youtube.com/watch?v=LpuPe81bc2w;License: Standard YouTube License, CC-BY
Binary Number System; Author: Neso Academy;https://www.youtube.com/watch?v=w7ZLvYAi6pY;License: Standard Youtube License