Share
Explore BrainMass

Greatest Common Divisor in Java

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).

Solution Summary

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

$2.19