作業
package aaa;
public class Counter
{
private int count = 0 ;
public void reset()
{
count = 0;
}
public void inc()
{
count=count+1 ;
}
public void dec()
{
count=count-1 ;
}
public void output()
{
System.out.println(+ count);
}
}
______________________________________
package count;
public class CounterDemo
{
public static void main(String[] args)
{
Counter counter= new Counter();
counter.output();
counter.inc();
counter.output();
counter.inc();
counter.inc();
counter.output();
counter.dec();
counter.output();
counter.reset();
counter.output();
}
}
OUTPUT:
0
1
3
2
0
0 Comments:
发表评论
<< Home