/*
* Counter.java
*
* Created on 2009年4月12日, 下午 11:01
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication16;
/**
*
* @author KFN
*/
public class Counter {
private int counter;
void reset()
{
counter = 0;
}
void inc()
{
++counter;
}
void dec()
{
--counter;
}
int getcounter()
{
return counter;
}
void output()
{
System.out.println(counter);
}
/** Creates a new instance of Counter */
public Counter() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Counter counter = new Counter();
counter.reset();
counter.inc();
counter.inc();
counter.inc(); //作為測試多做了2個加
counter.inc();
counter.dec();
counter.output();
// TODO code application logic here
}
}
沒有留言:
張貼留言