JAVA编写一个完整的计数器类Count,写出源代码

2024-12-17 13:35:05
推荐回答(1个)
回答1:

public class Count{ int countValue; Count(){ countValue=0; } public void increment() { countValue++; } public void decrement() { countValue--; } public void reset() { countValue=0; } public int getCountValue(){ return countValue; } public static void main(String args[]){ Count c = new Count(); c.increment(); System.out.println(c.getCountValue()); c.reset(); System.out.println(c.getCountValue()); } } 运行结果: 1 0

采纳哦