码迷,mamicode.com
首页 > 其他好文 > 详细

static静态变量-投票案例

时间:2018-12-05 22:55:07      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:pre   int   string   test   void   out   i+1   class   name   

 1 public class Voter {
 2     String name;  //名字
 3     private static int count;  //投票数
 4     
 5     public Voter() {}
 6     
 7     public Voter(String name) {
 8         this.name=name;
 9     }
10     
11     public void Vote() {
12         if(count==100) {
13             System.out.println("投票活动已经结束!");
14             return;
15         }else {
16             count++;
17             System.out.println(this.name+"欢迎您投票,当前票数是:"+count);
18         }
19     }
20 }
 1 //选民投票,每人只允许投票一次,当票数达到100时停止投票
 2 public class TestVoter {
 3 
 4     public static void main(String[] args) {
 5         for(int i=0;i<105;i++) {
 6             Voter v=new Voter("张三"+(i+1));
 7             v.Vote();
 8         }
 9     }
10 
11 }

 

static静态变量-投票案例

标签:pre   int   string   test   void   out   i+1   class   name   

原文地址:https://www.cnblogs.com/baichang/p/10073968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!