统计信息

  • 访问数:14572
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P5Q9

2008-04-08 19:11:58

天气: 晴朗 心情: 高兴

/*fileName:P5Q09
 * Name:Wang Chaoran
 * Description:
9 (Computing GCD)
Write a method that returns the greatest common divisor between two positive integers, using the following header:
public static int gcd(int m, int n)
Write a test program that computes gcd(24, 16) and gcd(255, 25).
*/

public class P5Q09{
  public static void main(String[] args){
    //Output
    System.out.println("gcd(24, 16) = "+gcd(24, 16));
    System.out.println("gcd(255, 25) = "+gcd(255, 25));
  }
  //Method
  public static int gcd(int m, int n){
   
    while(m != n){
    if(m > n)
     m = m - n;
    else
     n = n - m;
  }
    return m;
}
}


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd