Mon Apr 09, 2007 11:23 pm
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;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.