我写的java有问题.请帮我解决并解释

来源:百度知道 编辑:UC知道 时间:2024/07/07 14:48:00
public class aa
{
public static int cube(int a)
{
return a*a*a;
}
public static void modThree(int b)
{
int c=b%3;
System.out.println(c);
}
public static void main (String[]args)
{
int d=2;
int e=cube(d);
System.out.println(e);

int f=modThree(d);
System.out.println(f);}}
可是我把第一个void改成int了.也是不行.也是有问题

public class aa
{
public static int cube(int a)
{
return a*a*a;
}
public static void modThree(int b) //你定义成void 类型说明没有返回值;
{
int c=b%3;
System.out.println(c);
}
public static void main (String[]args)
{
int d=2;
int e=cube(d);
System.out.println(e);

int f=modThree(d); //但是你在这里把modThree(d)的返回值赋给了 f;
System.out.println(f);}}

前后不一致所以错了。你把那个void改成int就好了。

还有一点值得注意的就是你的类名的第一个字母应该是小写的,这是规定。

什么啊?

public class aa
{
public static int cube(int a)
{
return a*a*a;
}
public static void modThree(int b) //这个没有返回值
{
int c=b%3;
System.out.println(c);
}
public static void main (String[]args)
{
int d=2;
int e=cube(d);
System.out.println(e);

int f=modThree(d); //不可以写成这样,它没有返回值,所以不可以赋值.
System.out.println(f);}}

modThree方法写的不对,加上返回值,并且写上retu