Java 非法的表达式开始

publicclassJiaQi{publicstaticvoidmain(String[]args){publicinterfaceInterface{publicab... public class JiaQi
{
public static void main(String[] args)
{
public interface Interface
{
public abstract void ArrayStack ();
public abstract boolean isEmpty();
public abstract void makeEmpty();
public abstract void top();
public abstract void pop();
public abstract void topAndPop();
public abstract void push();
public static final int DEFAULT_CAPACITY = 10;
}

//System.out.println("Hello World!");
class text implements Interface
{
private int[] theArray;
private int topOfStack;
public void ArrayStack()
{
theArray = new int[DEFAULT_CAPACITY];
topOfStack = -1;
}

public boolean isEmpty()
{
return topOfStack == -1;
}

public void makeEmpty()
{
topOfStack = -1;
}

public void push(int x)
{
if(topOfStack + 1 == theArray.length)
System.out.println("over flow");
else
theArray[++topOfStack] = x;
}

public int top()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
return theArray[topOfStack];
}

public viod pop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
topOfStack--;
}

public int topAndPop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
return theArray[topOfStack--];
}
}
}
}

编译后
JiaQi.java:5: 非法的表达式开始
public interface Interface
^
JiaQi.java:5: 需要 ';'
public interface Interface
^
2 错误
------------------------------------
程序怎么回事呀?
------------------------------------

小弟有点不明白,我在网上查了下,怎么非法表达式开始错误分好多,具体怎么回事,高手能给总结下吗?
展开
 我来答
东桖柳83
2008-10-19 · TA获得超过599个赞
知道小有建树答主
回答量:603
采纳率:0%
帮助的人:379万
展开全部
public interface Interface
{
public abstract void ArrayStack ();
public abstract boolean isEmpty();
public abstract void makeEmpty();
public abstract void top();
public abstract void pop();
public abstract void topAndPop();
public abstract void push();
public static final int DEFAULT_CAPACITY = 10;
}

首先interface是JAVA的关键字你怎么能用它来当接口名呢,并且定义一个接口要独立出来,怎么能出现在类里面呢,

theArray = new int[DEFAULT_CAPACITY]; 数组那来一个默认长度啊.

public viod pop() 这里必须有类型啊不能是VOID
2008calm
2008-10-19
知道答主
回答量:22
采纳率:0%
帮助的人:0
展开全部
public class JiaQi
{

public interface Interface
{
public abstract void ArrayStack ();
public abstract boolean isEmpty();
public abstract void makeEmpty();
public abstract int top();
public abstract void pop();
public abstract int topAndPop();
public abstract void push();
public static final int DEFAULT_CAPACITY = 10;
}

//System.out.println("Hello World!");
class text implements Interface
{
private int[] theArray;
private int topOfStack;

public void ArrayStack()
{
theArray = new int[DEFAULT_CAPACITY];
topOfStack = -1;
}

public boolean isEmpty()
{
return topOfStack == -1;
}

public void makeEmpty()
{
topOfStack = -1;
}

public void push(int x)
{
if(topOfStack + 1 == theArray.length)
System.out.println("over flow");
else
theArray[++topOfStack] = x;
}

public int top()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
return theArray[topOfStack];
return 0;
}

public void pop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
topOfStack--;
}

public void push()
{

}

public int topAndPop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
return theArray[topOfStack--];
return 0;
}
}

public static void main(String[] args)
{ }
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式