星期一, 5月 08, 2006

Counter

package Lab7;

public class Counter {
private int count = 0 ;

public void reset()
{
count = 0;
System.out.println("reset counter,");
}

public void inc()
{
++count ;
System.out.println("counter+1,");
}

public void dec()
{
--count ;
System.out.println("counter-1,");
}

public void output()
{
System.out.println("counter now is :"+ count);
}

}
---------------
package Lab7;

public class CounterDemo {

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

0 Comments:

張貼留言

<< Home

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Taiwan License.