2008年4月28日 星期一

Lab counter

public class Counter
{
private int number;

public void reset()
{
number=0;
}
public void inc()
{
number=number+1;
}
public void dec()
{
number=number-1;
}
public void output()
{
System.out.println(number);
}
}


public class CounterMain
{
public static void main(String[] args)
{
Counter count;
count = new Counter();
count.reset();
count.inc();
count.inc();
count.dec();
count.output();
}
}

結果:













沒有留言: