我相当新的Java和我不知道为什么这段代码不编译。它有时也不会返回我的结果。有什么建议么?.class在我的方法预期的错误,有时缺少返回语句错误
public static char isPrime(int x)
{
for(int y=2;y<x;y++)
char result = 'r';
if(x%y==0)
result = 't';
else
result = 'f';
return result;
}
或
public static char isPrime(int x)
{
char result = 'r';
for(int y=2;y<x;y++)
if(x%y==0)
result = 't';
else
result = 'f';
return result;
}
你需要大括号。 – SLaks 2013-05-02 15:18:23
我应该在哪里添加它们? – user2340601 2013-05-02 15:22:20
你应该返回一个'boolean',而不是'char'。 – SLaks 2013-05-02 15:25:54