JAVA程序错误 帮忙看下 让它运行

来源:百度知道 编辑:UC知道 时间:2024/06/18 08:34:59
public class test {
public static xMethod1(int n, int 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 ;
}
}

就是这个程序 请帮忙看看为什么不能运行
纠正之后请先运行一下啊 谢谢

main 方法是必要的
但是xMethod1无返回值怎么能运行?
没有返回值最起码有个 void吧
写了 main方法 然后 加上 xMethod1的 void 测试可以
public class test {
public static [void] xMethod1(int n, int m) { //方法没有返回值 这里添加了void
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 ;
}
[//-------[]中是我添加的
public static void main(String args[])
{
/***
*运行代码
//*
}
]
}

晕。。。

public class test {
public static xMethod1(int n, int 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 ;
}
}
另外,没有调用?也不清楚你想要实现什么

public class test {
public static xMethod1(int n, int m) {
n+=m ;
x