java缺少返回语句

2025-03-06 12:21:31
推荐回答(5个)
回答1:

t1 方法的类型设置问题
如果像你写的那样 private int t1(int a){......} 这样你就需要返回一个int类型的数据
如果不需要返回值 你可以将t1修改为private void t1(int a){......}

回答2:

class Sub {
static int Sub(int n) {

if (n > 0) {
if ((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)) {
return 1;
}

else {
return 0;
}
} else if (n < 0) {
if ((-1 * n) % 400 == 1 && (-1 * n) % 3200 != 1) {
return 1;
}

else {
return 0;
}
} else if (n == 0) {
return 1;
}else //这里需要最后返回一个值
return n; //无法处理,默认返回n

}

}

回答3:

你的private方法t1声明,会返回一个int,而你在该方法的代码块中,却没有用return进行返回。

回答4:

t1方法缺少返回

private int t1(int a){
String str ="";
int sun = a/16;
int yushu = a%16;
str = ""+yushu;
while(sun > 0){
yushu = sun % 16;
sun = sun / 16;
str = yushu + str;
return XXX;----这里要有返回
}
System.out.println("16进制==="+str);

}

回答5:

这种题目不看补充无法回答,所以请回收。