cf试炼祭坛50秒技巧:JAVA 编程

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 00:12:13
import java.io.*;
class b
{
public static void main(String args[])throws IOException
{BufferedReader buf;
String str1,str2;
int i,x,y,m,num;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Intput 1:");
str1=buf.readLine();
x=Integer.parseInt(str1);
System.out.print("Intput 2:");
str2=buf.readLine();
y=Integer.parseInt(str2);
{if(x-y>0)
m=x/2;
else m=y/2;
}
for(i=1;i<=m;i++)
{
if(x%i=0)
{if(y%i=0) num=i;
}
}
System.out.println("最大公因数:"+num);
}
}
我编译的时候有两个地方错误 21-22行的“%”有错!我也不知道为什么?
别的地方我也检查过了!请各位帮帮忙看看!
是求两个数的最大公因数!
谢谢

= 是赋值不是判等
应该用 ==

否则表达式的值不是boolean型
会出编译错误

一楼说的没错