import java.util.Random;
interface DA0
{
int x0=0,x1=1,x2=2,x3=3,x4=4,x5=5,x6=6,x7=7,x8=8,x9=9;
}
class D1 implements DA0
{
Random rand =new Random();
int ask()
{
int p=0,i=0;
for(i=1;i<=100;i++)
p=(int)(100*rand.nextDouble());
if(p<1) return x0;
else if(p<10)return x1;
else if(p<20)return x2;
else if(p<30)return x3;
else if(p<40)return x4;
else if(p<50)return x5;
else if(p<60)return x6;
else if(p<70)return x7;
else if(p<80)return x8;
else return x9;


}
 public class jex7_5
{
public static void main(String[] args)
{
long p0,p1;
int i,j;
D1 k=new D1();
for(j=1;j<=5;j++)
{
p0=0;
for(i=1;i<=6;i++)
p0=p0*10+k.ask();
p1=k.ask();
if(p1==0||p1%2==0)p1=2;
else p1=1;
System.out.println(p1+ ""+p0);

}
}
}

出错提示:inner classes  cannot  have static  declarations怎么样修改?

解决方案 »

  1.   

    内部类不能由静态申明把 jex7_5类 放到一个单独的java文件中
      

  2.   

    把最后的4个大括号之一移到public class jex7_5 之前
      

  3.   


    import java.util.Random; interface DA0 { 
    int x0=0,x1=1,x2=2,x3=3,x4=4,x5=5,x6=6,x7=7,x8=8,x9=9; 
    } class D1 implements DA0 { 
    Random rand =new Random(); 
    int ask() { 
    int p=0,i=0; 
    for(i=1;i <=100;i++) 
    p=(int)(100*rand.nextDouble()); 
    if(p <1) return x0; 
    else if(p <10) return x1; 
    else if(p <20) return x2; 
    else if(p <30) return x3; 
    else if(p <40) return x4; 
    else if(p <50) return x5; 
    else if(p <60) return x6; 
    else if(p <70) return x7; 
    else if(p <80) return x8; 
    else return x9; 

     
    } public class jex7_5 { 
    public static void main(String[] args) { 
    long p0,p1; 
    int i,j; 
    D1 k=new D1(); 
    for(j=1;j <=5;j++){ 
    p0=0; 
    for(i=1;i<=6;i++) 
    p0=p0*10+k.ask(); 
    p1=k.ask(); 
    if(p1==0||p1%2==0) p1=2; 
    else p1=1; 
    System.out.println(p1+ ""+p0); 


    }
      

  4.   

    那个英文提示inner classes  cannot  have static  declarations 的意思是 内部类不能包含静态声明,
    很显然要么把内部类挪到外面,要么去掉静态声明,去掉静态声明很显然不对,那就把内部类挪到外面。
    方法:把最后的4个括号之一放到 public class jex7_5  的前面一行,或者直接另外定义一个类文件jex7_5。
      

  5.   

    出错提示:inner classes  cannot  have static  declarations 非静态内部类 不能有静态声明
    静态内部类可以有静态声明