关于java 非法的表达??及代码补充

来源:百度知道 编辑:UC知道 时间:2024/05/21 08:34:15
public String toString()
/*
Pre-condition: none
Post-condition: a String object is returned consisting of the
String representation of all items in the Queue,
from first to last in order, separated by " " and
contained within "<" and ">"
Informally: produce a String representation of the Queue
*/
{
Node c;
String s="";

trace("toString: toString starts");

if (isEmpty())
{
trace("toString: toString ends");
return "<>";
}
else
{
c=first;
while (c != null)
{
s=s.concat(c.getData().toString() + " ");
c=c.getNext();
}
trace("toString: toString ends");

return s;
}
}

public void trace(String s)
/*
Provide trace o

public String toString() 这句应该是定义了一个方法吧?定义在某个类中了吗?我对JAVA还在入门期,我觉得这是不是类的错误定义问题?小弟刚开始学JAVA;也很期待答案;请高手指点。

String是JAVA的关键字,是不能用作类的名字的

如果这是你的全部代码,那你应该是用public class开头的,而你缺少了class