日期:2014-05-20  浏览次数:20766 次

最大公约数?
import   java.math.*;
import   java.util.Scanner;
public   class   GCD   {
int   i;
int   j;
int   gcd;
int   max;

public   void   show()
{
System.out.println( "Pls   type   in:\n ");
Scanner   input=new   Scanner(System.in);
i=input.nextInt();
j=input.nextInt();

if(i%gcd==0)
{
if(j%gcd==0)
{
int   array[gcd];
max=math.max(array[gcd]);//这个怎么调用呢??
}
else
{
System.out.println( "Them   have   no   relationship ");
}
public   static   void   main()
{
System.out.println( "The   GCD   is "+max);
}
}
}

}


在调用MATH方法的时候ECLIPSE总是在那一行打叉

劳请各位大哥帮小弟斧正....

困意非常   会周公也....

------解决方案--------------------
这样用....错误太多了,只能重写了

import java.util.*;

public class GCD {
static int i;

static int j;

static int gcd;

static int max;

public static void main(String[] args) {
show();

}

public static void show() {
System.out.println( "Pls type in: ");
Scanner input = new Scanner(System.in);
i = input.nextInt();
j = input.nextInt();
ArrayList <Integer> al = new ArrayList <Integer> ();
al.add(1);
for (gcd = 2; gcd <= j || gcd <= i; gcd++) {
if ((i % gcd == 0) && (j % gcd == 0))
al.add(gcd);
}
max = Collections.max(al);
if (max == 1)
System.out.println( "Them have no relationship ");
else
System.out.println( "The GCD is " + max);

}

}