初学java,一个小错误解决不了
来源:百度知道 编辑:UC知道 时间:2024/05/01 21:26:01
import java.util.*;
public class JAVA2_9 {
class Compare
{
public int Max(int x,int y)
{
if(x>=y)
return(x);
else return(y);
}
public int Min(int x,int y)
{
if(x<=y)
return(x);
else return(y);
}
}
public static void main(String args[])
{
int anArray[];int Max=0;int Min=10000;
int i;
anArray=new int[10];
Scanner s=new Scanner(System.in);
for(i=0;i<anArray.length;i++)
anArray[i]=s.nextInt();
Compare c=new Compare();//编译器说这行有错
for(i=0;i<10;i++)
Max=c.Max(Max, Min);
System.out.println(Max);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type JAVA2_9 is accessible. Must qualify the allocation with an enclosing instance of type JAVA2_9 (e.g. x.new A() where x is an in
public class JAVA2_9 {
class Compare
{
public int Max(int x,int y)
{
if(x>=y)
return(x);
else return(y);
}
public int Min(int x,int y)
{
if(x<=y)
return(x);
else return(y);
}
}
public static void main(String args[])
{
int anArray[];int Max=0;int Min=10000;
int i;
anArray=new int[10];
Scanner s=new Scanner(System.in);
for(i=0;i<anArray.length;i++)
anArray[i]=s.nextInt();
Compare c=new Compare();//编译器说这行有错
for(i=0;i<10;i++)
Max=c.Max(Max, Min);
System.out.println(Max);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type JAVA2_9 is accessible. Must qualify the allocation with an enclosing instance of type JAVA2_9 (e.g. x.new A() where x is an in
Compare c=new Compare();//编译器说这行有错
Compare 放错位置了 应该这样;
import java.util.*;
public class JAVA2_9 {
public static void main(String args[])
{
int anArray[];int Max=0;int Min=10000;
int i;
anArray=new int[10];
Scanner s=new Scanner(System.in);
for(i=0;i<anArray.length;i++)
anArray[i]=s.nextInt();
Compare c=new Compare();//编译器说这行有错
for(i=0;i<10;i++)
Max=c.Max(Max, Min);
System.out.println(Max);
}
}
class Compare
{
public int Max(int x,int y)
{
if(x>=y)
return(x);
else return(y);
}
public int Min(int x,int y)
{
if(x<=y)
return(x);
else return(y);
}
}