java程序的错误 帮忙看下

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:35:44
public class test {
public static method1(int n, m) {
n+=m ;
xMethod(3,4) ;
}

public static int xMethod (int n) {
if (n>0) return 1;
else if (n==0) return 0 ;
else if (n<0) return -1 ;
}
}

就是这个程序 帮忙纠错吧
纠正以后请朋友们运行一下 看是不是能运行

2个错误,1个建议。改为
public class Test {//这里见注3
public static method1(int n, int m) {//这里见注1
n+=m ;
xMethod(n) ;//这里见注2
}

public static int xMethod (int n) {
if (n>0) return 1;
else if (n==0) return 0 ;
else if (n<0) return -1 ;
}
}

1.method1的形参m没有指定类型,应该改为int m
2.xMethod 只需要一个参数
3.只是建议。java中建议类名首字母大写。养成良好的书写习惯非常有好处的。

第一个方法中:xMethod(3,4);而声明这个方法只有一int n;加上int m看看

改正:
public class Test {
public static void method1(int n, int m) {
n+=m ;
new Test().xMethod(n) ;
}

public static int xMethod (int n) {
if (n>0) return 1;
else if(n==0) return 0 ;
else return -1 ;
}
}

参数数目都不对啊

public class test {
public static method1(int n, m) {
n+=m ;
xMethod(3) ;
}

public static int xMethod (int n) {
if (n>0) retu