여기에 새 Java 사용자가 있습니다. 수업 과제에 도움이 필요합니다. 이 코드는 어떤 기능을합니까? 그리고 왜 내가 스택에 오류가 있어요 = 새로운 스택 (10); 및 s.top() 메소드. 크기를 받아들이는 생성자가 없습니다 http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html클래스 인스턴스화시 오류 받기
:
public class StackExample
{
public static void main(String[] args)
{
Stack s = new Stack(10);
System.out.println("Adding 33 and 47 to stack.");
// push adds the item to the top of the stack
s.push(33);
s.push(47);
System.out.println("Top of stack: " + s.top());
System.out.println("Items in stack: " + s.size());
// pop removes the top item
System.out.println("Removing top item.");
s.pop();
System.out.println("Top of stack: " + s.top());
System.out.println("Items in stack: " + s.size());
System.out.println("Adding a new item.");
s.push(3);
System.out.println("Top of stack: " + s.top());
System.out.println("Items in stack: " + s.size());
}
}
어떤 오류가 발생합니까? –
's.top() 대신's.peek()'을 시도하십시오 – svs
어떤 오류가 발생합니까? – christopher