//文件名:Factorial.Java
package book.basic;public class Factorial
{
public long getFactorial(int n)
{
if((n<0)||(n>17))
{
System.err.println(" n值的范围必须在[0,17]内!");
return -1;
}
else if(n==0)
{
return 1;
}
else
{
long result=1;
for(;n>0;n--)
result*=n;
}
return result;
}
}
public static void main (String[] args)
{
Factorial test=new Factorial();
System.out.println(test.getFactorial(15) );
} 感觉像是很简单的问题,但就是找不出来错误信息如下:
Factorial.java:26: 需要 "class" 或 "interface"
public static void main (String[] args)
package book.basic;public class Factorial
{
public long getFactorial(int n)
{
if((n<0)||(n>17))
{
System.err.println(" n值的范围必须在[0,17]内!");
return -1;
}
else if(n==0)
{
return 1;
}
else
{
long result=1;
for(;n>0;n--)
result*=n;
}
return result;
}
}
public static void main (String[] args)
{
Factorial test=new Factorial();
System.out.println(test.getFactorial(15) );
} 感觉像是很简单的问题,但就是找不出来错误信息如下:
Factorial.java:26: 需要 "class" 或 "interface"
public static void main (String[] args)
解决方案 »
- 在eclipse运行不出来下面的代码,请高人指点一下,小弟初学,迷茫中,照着书打的,这个是制作一个固定资产的添加界面
- Jdk6 win7上安装问题
- 关于容器的add set方法
- eclips模板
- 怎样把界面数据传输到事件中
- 正则: "一行的结尾" $ 为什么不好使??
- hibernate映射必须要设置OID,难度硬要在数据库表中加一个id吗?
- 各位牛人:我求用ant将文件上传到远程ftp服务器的指定目录的方法!
- 入门问题:如何从键盘录入一个整数,让其存入int数值中
- 我下栽了一个jdk1.3现在想来开发和数据库连接的问题,他有自己带的jdbc吗,支持什么数据库,高手指点拉?
- 关于线程方面的问题
- 怎么把map的key和value分别遍利出来啊?
楼主【JAVA_mentu】截止到2008-07-14 20:55:08的历史汇总数据(不包括此帖):
发帖的总数量:6 发帖的总分数:110 每贴平均分数:18
回帖的总数量:28 得分贴总数量:10 回帖的得分率:35%
结贴的总数量:6 结贴的总分数:110
无满意结贴数:1 无满意结贴分:20
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:16.67 % 无满意结分率:18.18 %
敬礼!
{
public long getFactorial(int n)
{
if((n<0)||(n>17))
{
System.err.println(" n值的范围必须在[0,17]内!");
return -1;
}
else if(n==0)
{
return 1;
}
else
{
long result=1;
for(;n>0;n--)
result*=n;
}
return result;
}
public static void main (String[] args)
{
Factorial test=new Factorial();
System.out.println(test.getFactorial(15) );
}
}
if ((n < 0) || (n > 17)) {
System.err.println(" n值的范围必须在[0,17]内!");
return -1;
} else if (n == 0) {
return 1;
} else {
result = 1;
for (; n > 0; n--) {
result *= n;
}
}
return result;
} public static void main(String[] args) {
Factorial test = new Factorial();
System.out.println(test.getFactorial(15));
}
}
这里result没有定义.
{
Factorial test=new Factorial(); System.out.println(test.getFactorial(15) );
}
很明显。。main()方法跑类外面来了。。------------------------------------------------------------public class Test {
public static void main(String[] args) {
}}
{
public long getFactorial(int n)
{
long result = 0;
if((n<0)||(n>17))
{
System.err.println(" n值的范围必须在[0,17]内!");
return -1;
}
else if(n==0)
{
return 1;
}
else
{
result=1;
for(;n>0;n--)
result*=n;
}
return result;
}
public static void main (String[] args)
{
Factorial test=new Factorial();
System.out.println(test.getFactorial(15) );
}
}
Caused by: java.lang.ClassNotFoundException: Factoria
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Factoria. Program will exit.
Exception in thread "main"
[code=BatchFile]java book.basic.Factorial[/code]
试试