/*
【程序11】
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月
后每个月又生一对兔子,假如兔子都不死,问12个月内每个月的兔子总数为多少? */
class tuzi
{
public static void main(String []args)
{
int t=2,y,i,sum=0,n;
System.out.println("请输入月份");
try
{
n=new Integer(args[0]);
}
catch(Exception e)
{
System.out.println(e.Message()+"请输入数字");
}
for(y=1;y<=n;y++)
{
//for(t=2;;t++)
//{
if(y%3==0)
{
for(i=2;i<=y;i=(i+2))
{
t=2*i;
}
}
//}
System.out.println("第"+y+"月的兔子个数为:"+t);
sum=sum+t;
}
y=y-1;
System.out.println("这"+y+"个月的兔子总数为:"+sum);
}
}编译时老出现这个问题
F:\javastu\lianxi>javac tuzi.java
tuzi.java:13: incompatible types
found : java.lang.Integer
required: int
n=new Integer(args[0]);
^
tuzi.java:15: cannot access Exception
bad class file: .\Exception.java
file does not contain class Exception
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
catch(Exception e)
我看了环境设置,并没有错!为什么会出现这个错误??谢谢!
^
【程序11】
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月
后每个月又生一对兔子,假如兔子都不死,问12个月内每个月的兔子总数为多少? */
class tuzi
{
public static void main(String []args)
{
int t=2,y,i,sum=0,n;
System.out.println("请输入月份");
try
{
n=new Integer(args[0]);
}
catch(Exception e)
{
System.out.println(e.Message()+"请输入数字");
}
for(y=1;y<=n;y++)
{
//for(t=2;;t++)
//{
if(y%3==0)
{
for(i=2;i<=y;i=(i+2))
{
t=2*i;
}
}
//}
System.out.println("第"+y+"月的兔子个数为:"+t);
sum=sum+t;
}
y=y-1;
System.out.println("这"+y+"个月的兔子总数为:"+sum);
}
}编译时老出现这个问题
F:\javastu\lianxi>javac tuzi.java
tuzi.java:13: incompatible types
found : java.lang.Integer
required: int
n=new Integer(args[0]);
^
tuzi.java:15: cannot access Exception
bad class file: .\Exception.java
file does not contain class Exception
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
catch(Exception e)
我看了环境设置,并没有错!为什么会出现这个错误??谢谢!
^
初始化一下还有 n= Integer.parseInt(args[0]);catch(java.lang.Exception e)
{
System.out.println(e.getMessage()+"请输入数字");
}这样改了代码就没有问题了Exception 这个Exception是你自己定义的吗