Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Greatest Comman Divisor using Java

Mon Apr 09, 2007 11:23 pm

This is the code i made to get greatest comman divisor of two integer numbers :
java code
package javaapplication5;

import java.util.Scanner;

/**
*
* @author sami
*/
public class GCD {

/** Creates a new instance of GCD */
public GCD() {
System.out.println("Greatest Comman Divisor ");
Scanner inscan=new Scanner(System.in);
System.out.println("Please enter the first number ");
a=inscan.nextInt();
System.out.println("Please enter the second number ");
b=inscan.nextInt();
System.out.println("The GCD("+a+","+b+")= "+get_GCD() );
}
public int get_GCD()
{
int remmender;
while(b>0)
{
remmender=a%b;
a=b;
b=remmender;
}
return a;
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new GCD();
// TODO code application logic here
}

private int a;
private int b;

}




Post a reply
  Related Posts  to : Greatest Comman Divisor using Java
 greatest common divisor (GCD)     -  
 Greatest common divisor     -  
 greatest common divisor-code-c     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Java course     -  
 What is Java API?!!!     -  
 java or .net     -  
 need help in java     -  
 Using FTP in java     -  
 what is java     -  

Topic Tags

Java Algorithms