有关Java的,会的帮忙改改啊!运行结果不对啊!

来源:百度知道 编辑:UC知道 时间:2024/06/27 07:53:32
package shiyan2_1;

import java.io.*;
public class shiyan2_1 {
public static void main(String[] args) throws IOException{
int a,b;
byte buf[]=new byte[10];
String str;
System.out.print("请输入第一个数:");
System.in.read(buf);
str=new String(buf);
a=Integer.parseInt(str.trim());
System.out.print("请输入第二个数:");
System.in.read(buf);
b=Integer.parseInt(str.trim());
shiyan2_1 t=new shiyan2_1();
t.xh(a,b);
t.digui(a,b);
}
void xh(int n,int m) {
while(true){
int r =m%n;
if (r == 0) {
System.out.println("最大公约数为" + n);
break;
}
m = n;
n = r;
}
}
void digui(int n,int m){
shiyan2_1 p1=new shiyan2_1();
int r=m%n;
if(r==0)
System.out.println("最大公约数为" + n);
else p1.

帮你改好了,你中间掉了句str=new String(buf);
import java.io.*;
public class shiyan2_1 {
public static void main(String[] args) throws IOException{
int a,b;
byte buf[]=new byte[10];
String str;
System.out.print("请输入第一个数:");
System.in.read(buf);
str=new String(buf);
a=Integer.parseInt(str.trim());

System.out.print("请输入第二个数:");
System.in.read(buf);
str=new String(buf);
b=Integer.parseInt(str.trim());

shiyan2_1 t=new shiyan2_1();
t.xh(a,b);
t.digui(a,b);
}
void xh(int n,int m) {
while(true){
int r =m%n;
if (r == 0) {
System.out.println("最大公约数为" + n);
break;
}
m = n;
n = r;
}
}
void digui(int n,int m){
shiyan2_1 p1=new shiyan2_1();
int r=m%n;
if(r==0)
System.out.println("最大公约数为" + n);
else p1.digui(r,n);
}

}