有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用静态

我很难做到这一点。我得让司机保持原样。我的StaticCounter课程需要做什么

public class Driver1
{
public static void main(String[] args)
   {
   for (int i=0; i<10; i++)
      {
         System.out.println("Counter returned: " +
         StaticCounter.count());
      }
   }
}

StaticCounter.java
public class StaticCounter
{
   public static int count()
   {
       static int id;
       id=count++;
    }
}

共 (1) 个答案

  1. # 1 楼答案

    我想你可能在寻找这样的东西:

    public class StaticCounter{
    
        private static int count;
    
        public static int count(){
            return count++; //or ++count if you want to increment before getting value
        }
    
    }