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