Purchase Solution

Greatest Common Divisor in Java

Not what you're looking for?

Ask Custom Question

I have to write an interactive program that will find the Greatest common divisor between two inputted integers.

Here is what I have so far.

//
//
//
// This Program will find the greatest common divisor between two inputted integers.
//
//

import java.io.*;

public class space11{

static BufferedReader keyboard =
new BufferedReader( new InputStreamReader(System.in));

public static void main(String args[]) throws IOException{

System.out.println();
System.out.println();

int divisor;
int small_number, larger_number;

System.out.println("This Program will fins the GCD between two numbers");
System.out.println();
System.out.print("Please enter the first number here: ");
first_number = Integer.parseInt(keyboard.readLine().trim());
System.out.println();
System.out.print("Please enter the second number here: ");
second_number = Integer.parseInt(keyboard.readLine().trim());
System.out.println();

for ( divisor = 2 ; divisor <= small_number; divisor++);
{

if ( small_number % divisor == 0 && larger_number % divisor ==0).

Purchase this Solution

Solution Summary

The greatest common divisor in Java are examined in the solution.

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.