我似乎无法让这个错误消失。它说在最后一行:解析时到达文件末尾,有人可以帮我吗?
class scanner
{
class Factorial
{
public static void main(String args[])
{
int n, c, fact;
System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact *c;
System.out.println("Factorial of "+n+" is = "+fact);
}
}
}
答案 0 :(得分:0)
你最后错过了一个括号“}”,这就是它抛出错误的原因。
更正了代码语法,也解决了其他错误。
编辑:正如@Pshemo所说,你不需要“类扫描器”,所以我评论说,但你可以删除评论真实的import java.util.Scanner;
//public static class scanner
//{
public static class Factorial
{
public static void main(String args[])
{
int n, c, fact;
System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact *c;
System.out.println("Factorial of "+n+" is = "+fact);
}
}
}
//}