online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
import java.util.*; //抽象集合 interface Aggregate { public void add(Object obj); public void remove(Object obj); public Iterator getIterator(); } //具体集合 class ConcreteAggregate implements Aggregate { private List<Object> list=new ArrayList<Object>(); public void add(Object obj) { list.add(obj); } public void remove(Object obj) { list.remove(obj); } public Iterator getIterator() { return(new ConcreteIterator(list)); } } //抽象迭代器 interface Iterator { Object first(); Object next(); Object previous(); Object last(); boolean hasNext(); } //具体迭代器 class ConcreteIterator implements Iterator { private List<Object> list=null; private int index=-1; public ConcreteIterator(List<Object> list) { this.list=list; } public boolean hasNext() { if(index<list.size()-1) { return true; } else { return false; } } public Object first() { index=0; Object obj=list.get(index);; return obj; } public Object next() { Object obj=null; if(this.hasNext()) { obj=list.get(++index); } return obj; } public Object previous() { Object obj=null; if(this.hasNext()) { obj=list.get(--index); } return obj; } public Object last() { index=list.size()-1; Object obj = list.get(index); return obj; } } public class Main { public static void main(String[] args) { Aggregate ag = new ConcreteAggregate(); ag.add("建國中學"); ag.add("師大附中"); ag.add("成功高中"); ag.add("松山高中"); ag.add("中崙高中"); ag.add("麗山高中"); System.out.print("學校列表:"); Iterator it = ag.getIterator(); while(it.hasNext()) { Object ob=it.next(); System.out.print(ob.toString()+"\t"); } Object ob=it.first(); System.out.println("\nFirst:"+ob.toString()); Scanner scanner = new Scanner(System.in); boolean end = false; while (!end){ System.out.println("請輸入選項(1:第一所;2:下一所;3:最後一所):"); int num = scanner.nextInt(); if (num == 1){ System.out.println("顯示的學校為:" + it.first().toString()); } else if (num == 2){ if (it.hasNext()){ System.out.println("顯示的學校為:" + it.next().toString()); } else { System.out.println("已經到最後一筆"); } } else if (num == 3){ System.out.println("顯示的學校為:" + it.last().toString()); } else { System.out.println("請輸入正確指令" ); } } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue