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总是在那一行打叉劳请各位大哥帮小弟斧正....困意非常 会周公也....

解决方案 »

  1.   

    这样用....错误太多了,只能重写了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); }}
      

  2.   

    JAVA有时就是麻烦 别的语言写简单多了
      

  3.   

    import java.math.*;
    import java.util.Scanner;public class TestGongyue {
    int i;
    int j;
    int max; public void show()
    {
    System.out.println("Pls type in one:\n");
    Scanner input=new Scanner(System.in);
    i=input.nextInt();
    System.out.println("Pls type in second:\n");
    j=input.nextInt();

    max = Math.min(i, j);
    if(max == 1){
    System.out.println("最大公约数是: " + max);
    }
    for(;max > 0;max--){
    if(i%max == 0 && j%max == 0){
    System.out.println("最大公约数是: " + max);
    break;
    }
    }
    }

    public static void main(String[] args){
    TestGongyue s = new TestGongyue();
    s.show();
    }}
      

  4.   


      max = Math.min(i, j);
    if(max == 1){
    System.out.println("最大公约数是: " + max);
    }
    for(;max > 0;max--){
    if(i%max == 0 && j%max == 0){
    System.out.println("最大公约数是: " + max);
    break;
    }
    }
    }
    --------------------------------int i = Integer.MaxValue;
    int j = i - 1;
    看看是不是很可以?
    至少数秒
    数论都学哪儿去了?
    int gongyue(int i , int j )
    {
        if (i > j)
    {
        int temp = i % j ;
      if (temp == 0)
    {
    return j;
    }
    return gongyue(i,temp);
    }
    }
      

  5.   

    这是按楼主的方法帮楼主改错,又不是在讨论算法
    要说算法,一个while搞定,还用递归?
    public static int gcd(int a, int b) {
    int r;
    while(b!=0) {
    r = a % b;
    a = b;
    b = r;
    }
    return a;
    }
      

  6.   

    不知道楼上到底在说什么?
    ------
    int i = Integer.MaxValue;
    int j = i - 1;
    看看是不是很可以?
    至少数秒
    ----------------
    这个对吗?你运行过吗?就贴上来!
    还有这个:
    ------
    int gongyue(int i , int j )
    {
    if (i > j)
    {
    int temp = i % j ;
    if (temp == 0)
    {
    return j;
    }
    return gongyue(i,temp);
    }
    }
    ------
    你认为你的方法写全了吗?能编译过去吗?给人讲问题要自己先写对.
      

  7.   

    全球华人中小企业协会
    中小企业协会
    华人中小企业协会
    注册香港公司
    香港公司注册
    注册香港公司
    香港公司注册
    香港公司
    注册香港公司问与答
    香港银行开户
    银行开户
    香港公司
    香港公司注册
    离岸公司注册
    注册海外公司
    公司注册
    美国公司注册
    注册美国公司
    注册英国公司
    英国公司注册
    BVI公司注册
    注册BVI公司
    香港律师公证
    购买现成香港公司
    注册商标
    商标注册
    香港商标注册
    注册香港商标
    注册中国商标
    中国商标注册
    知识产权
    中国知识产权
    香港知识产权
    专利申请
    香港公司报税
    香港公司审计
    香港公司法定秘书
    书号/刊号/书刊号
    香港公司商务秘书
    香港公司核数
    条形码
    香港公司年报
    香港公司年审