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

第一次迭代作业

时间:2016-12-23 01:00:13      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:判断   选择   rgs   定义   比赛   结束   for   array   param   

  1 import java.util.Scanner;
  2 import java.util.Arrays;
  3 
  4 
  5 
  6 public class Mian {
  7 
  8     /**
  9      * @param args
 10      */
 11     public static void main(String[] args) {
 12         // TODO Auto-generated method stub
 13         int[][] scoreArr = new int[5][2];// 定义二维数组,用于记录每局比赛分数
 14         int redfang = 0;
 15         int bluefang = 0;// 定义红蓝变量,用于判断红蓝整场比赛输赢
 16 
 17         System.out.println("***********欢迎进入排球计分系统***********");
 18         System.out.println();
 19         for (int j = 0;; j++) {
 20             System.out.println("\t请选择您的操作:");
 21             System.out.println("1、开始一局比赛\t2、查询一局比分\t3、退出");
 22             Scanner scan = new Scanner(System.in);
 23             String operate = scan.next();// 选择操作的系统
 24             if (j <5) {
 25                 switch (operate) {
 26                 case "1": {// 开始一局新比赛
 27 
 28                     System.out.println("第" + (j + 1) + "局比赛开始!");
 29                     boolean flog1 = false;
 30                     boolean flog2 = false;// 定义标志位,用于判断本局比赛红蓝方的输赢
 31 
 32                     int redScore = 0;
 33                     int blueScore = 0;// 定义每局比赛红蓝方基础分数
 34 
 35                     for (int i = 0; i < 30; i++) {
 36                         System.out.println("当前比分为:\n\t红方:" + redScore + "\t蓝方:" + blueScore);
 37                         System.out.println("请选择加分队伍序号:\n\t1、蓝方\t2、红方");
 38                         int score = scan.nextInt();
 39                         if(score==1||score==2){
 40                         if (score == 1) {// 为蓝方加分
 41                             redScore += 2;// 红方分数+2分
 42                             if (redScore >= 5) {// 率先到达分数,则赢
 43                                 scoreArr[j][0] = redScore;// 把红方分数写入二维数组
 44                                 scoreArr[j][1] = blueScore;// 把蓝方分数写入二维数组
 45                                 flog1 = true;// 判断本局比赛红方赢
 46                                 break;
 47                             } else {
 48                                 continue;
 49                             }
 50 
 51                         }
 52                         if (score == 2) { // 为红方加分
 53                             blueScore += 2;//蓝方分数+2
 54                             //率先达到,赢
 55                             if (redScore >= 5) {
 56                                 scoreArr[j][0] = redScore;//红方分数写进二维数组
 57                                 scoreArr[j][1] = blueScore;//把蓝方分数写进二维数组
 58                                 flog2 = true;//判断本局比赛蓝方赢
 59 
 60                                 break;
 61                             } else {
 62                                 continue;
 63                             }
 64                         }
 65                         }else{
 66                             System.out.println("输入不符合要求请重新输入");
 67                         }
 68                         
 69                     }
 70                     System.out.println("本局比赛结束!");
 71                     System.out.println("比分为:\t\t红方:" + redScore + "蓝方:" + blueScore);
 72                     if (flog1) {// 如果蓝方flog1为true
 73                         redfang++;// 蓝方总分+1
 74                         System.out.println("\t本局红方胜利");
 75                         if (redfang >= 3) {// 蓝方总分=3,蓝方赢
 76                             System.err.println("比赛红方胜利,全部比赛结束!请选择其他操作:");
 77                         }
 78                     }
 79                     if (flog2) {// 同上
 80                         bluefang++;
 81                         System.out.println("\t本局蓝方胜利");
 82                         if (bluefang >= 3) {
 83                             System.err.println("比赛蓝方胜利,全部比赛结束!");
 84                         }
 85                     }
 86                     continue;
 87                 }
 88                 case "2":
 89                     System.out.println("您要查询哪一局的分数:");
 90                     int choiseJ = scan.nextInt();
 91                     // 输出二维数组对应的分数
 92                     System.out.print("蓝方:红方==>");
 93                     System.out.print(scoreArr[choiseJ - 1][0] + ":");
 94                     System.out.println(scoreArr[choiseJ - 1][1]);
 95                     break;
 96                 case "3":
 97                     System.exit(0);
 98                     break;
 99                 }
100                 continue;
101             } else {
102                 System.err.println("比赛已经全部结束!请选择其他操作:");
103                 continue;
104             }
105 
106         }
107 
108     }
109 
110 }

这是第一次迭代的作业,内容大概完整,功能都已实现。

由于很多用法都已经忘记,在同学的帮助下完成这次作业,运行结果在控制台上,没有界面化,操作很不方便,以后会渐进改进。

第一次迭代作业

标签:判断   选择   rgs   定义   比赛   结束   for   array   param   

原文地址:http://www.cnblogs.com/yang19950425/p/6213133.html

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