A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 赵海洋 于 2013-7-16 09:32 编辑

由于22期即将开班,23期报名火热,特此推出22,23期和云舞联合重磅答题活动!!!

技术分计算:

    1.两次发题目之间是答题时间,跟下一次发题时间一样时或之前,答题有效。
没有做代码题的抢答分扣一半,超时的,抢答题总共扣除2/3。
    2.代码题上限五分。
    3.不回复都在哪一层抢答的,抢答分不给,希望谅解。


第一部分:抢答!
      1.一共十三道题,第一个正确回答技术分加2分,其他正确回答加一分,错误回答不给分。
      2.十三道题每隔5分钟版主会更新一道题,一直到十三道题更新完毕,结束抢答,版主会统计谁是超级幸运星
      3.赶快复习知识点吧,注意,都是基础题!!!
第二部分:代码题!
      1. 抢答结束后会有一道代码题,代码题不分先后顺序,回答时间在晚上10:00之前即可。
      2.由于考虑今晚工作量问题,所以给大家一个小时的代码题答题时间。代码题是基础题,请自己作答,勿抄袭、百度类似题等。
注意:
          1,抢答题时间初步定为晚上800~9:00,请互相转告,勿失良机哦~~~
        2,如果做了抢答题而没有做代码题,分数减半,同样两道题都做的,分数在原来基础上加1
        3,代码题初步定为晚上9:05分给题,请大家按时刷新看题。
        4.以上分数都是指技术分。
        5.请大家在做完抢答题后回复自己都是在哪几楼回答的问题,方便版主们统计,谢谢大家。
     6.加分会在活动结束后由版主统计,加分。请大家答题后不要着急,预计工作量会有些大,所以请大家耐心等待加分。
        7.如答题后有未加分情况,请联系版主。

代码题:   请用java语言做一个猜拳小程序。
          1.需要用到的知识点:泛型、继承、封装、多态、伪随机数、IO流等
          2.定义三个人物相对应不同的困难程度。
          3.完全开放式答题,你能做成什么样的,就做成什么样
          4.结果要截图出来,不在一个楼的注明是哪几个楼
      5.技术分到底给多少,就看你的了
      6.回复的时候,记得注明自己的抢答都在哪几个楼!
      7.不做代码题,抢答分会减少的哦!

抢答结果:       恭喜诸隆隆、王婧远、张洪慊、280270738、亲雨泽、阿凡提不买驴、iBadboy、toShareBeauty、李征、狼王  十题全答,鼓励技术分1分.
       草帽路飞答题9题,本次鼓励技术分1分,下次不予以鼓励。
       恭喜诸隆隆获得抢答题技术分12分,十题全答,抢答题部分共得13分技术分!!
       恭喜王婧远获得抢答题技术分11分,十题全答,抢答题部分共得12分技术分!!
       本次幸运星是诸隆隆!!!恭喜咯~~~
       请大家核实自己的得分情况,因为工作量较大,如有加错,请论坛联系版主或qq。【版主qq请在技术分加分细则中查找】




代码题.jpg (15.1 KB, 下载次数: 2)

代码题.jpg

评分

参与人数 1技术分 +2 黑马币 +30 收起 理由
万琪 + 2 + 30 淡定

查看全部评分

241 个回复

正序浏览
亲雨泽 发表于 2013-7-16 00:36
输出结果:
----------------欢 迎 进 入 游 戏 世 界----------------

抢答题回复在:7楼,18楼,27楼,41楼,76楼,83楼,102楼,123楼,142楼
回复 使用道具 举报
  1. package com.game.guess;

  2. /**
  3. * 计算机类
  4. *
  5. */
  6. public class Computer {
  7.        String name = "电脑"; // 名字
  8.        int score = 0;;       // 积分
  9.       
  10.        /**
  11.         * 出拳
  12.         * @return 出拳结果:1.剪刀 2.石头 3.布
  13.         */
  14.        public int showFist(){
  15.                // 产生随机数
  16.                int show = (int)(Math.random()*10)%3 + 1;  //产生随机数,表示电脑出拳
  17.               
  18.                // 输出出拳结果并返回
  19.                switch(show){
  20.                   case 1:
  21.                           System.out.println(name+"出拳: 剪刀");
  22.                           break;
  23.                   case 2:
  24.                           System.out.println(name+"出拳: 石头");
  25.                           break;
  26.                   case 3:
  27.                           System.out.println(name+"出拳: 布");
  28.                           break;
  29.                }
  30.                return show;
  31.        }
  32. }
复制代码
  1. package com.game.guess;
  2. import java.util.Scanner;

  3. /**
  4. * 游戏类
  5. *
  6. */
  7. public class Game {
  8.     Person person;       //甲方
  9.     Computer computer;   //乙方
  10.     int count;           //对战次数
  11.        
  12.     /**
  13.      * 初始化
  14.      */
  15.     public void initial(){
  16.             person = new Person();
  17.             computer = new Computer();
  18.             count = 0;
  19.     }
  20.                
  21.     /**
  22.      * 开始游戏
  23.      */
  24.         public void startGame() {
  25.                
  26.                 System.out.println("----------------欢 迎 进 入 游 戏 世 界----------------");
  27.                 System.out.println("\n\t\t******************");
  28.                 System.out.println  ("\t\t**  猜拳, 开始    **");
  29.                 System.out.println  ("\t\t******************");
  30.                
  31.                 System.out.println("\n出拳规则:1.剪刀 2.石头 3.布");
  32.                
  33.                 Scanner input = new Scanner(System.in);
  34.                 String exit = "n";  // 退出系统
  35.                
  36.                 do{
  37.                         initial();  // 初始化
  38.                         /*选择对方角色*/
  39.                         System.out.print("请选择对方角色(1:刘备 2:孙权 3:曹操): ");
  40.                        
  41.                         int role = input.nextInt();
  42.                         if(role == 1){
  43.                                 computer.name = "刘备";
  44.                         }else if(role == 2){
  45.                                 computer.name = "孙权";
  46.                         }else if(role == 3){
  47.                                 computer.name = "曹操";
  48.                         }   
  49.                        
  50.                         // 输入用户姓名
  51.                         /*输入用户姓名*/
  52.                         System.out.print("请输入你的姓名:");
  53.                         person.name = input.next();
  54.                        
  55.                         System.out.println(person.name+"  VS  "+computer.name+"  对战\n");
  56.                         // 扩展功能1结束
  57.                        
  58.                         System.out.print("要开始吗?(y/n) ");
  59.                         String start = input.next();  // 开始每一局游戏
  60.                        
  61.                        
  62.                         int perFist;   //用户出的拳
  63.                         int compFist;  //计算机出的拳
  64.                        
  65.                         while(start.equals("y")){
  66.                         /*出拳*/
  67.                                 perFist = person.showFist();
  68.                                 compFist = computer.showFist();
  69.                                 /*裁决*/
  70.                                 if((perFist == 1 && compFist == 1) || (perFist == 2 && compFist == 2) || (perFist == 3 && compFist == 3)){
  71.                                         System.out.println("结果:和局,真衰!嘿嘿,等着瞧吧 !\n");  //平局
  72.                                 }else if((perFist == 1 && compFist == 3) || (perFist == 2  && compFist == 1) || (perFist == 3 && compFist == 2)){
  73.                                         System.out.println("结果: 恭喜, 你赢了!");  //用户赢
  74.                                         person.score++;
  75.                                 }else{
  76.                                         System.out.println("结果说:^_^,你输了,真笨!\n");  //计算机赢
  77.                                         computer.score++;
  78.                                 }
  79.                                 count++;
  80.                                 System.out.print("\n是否开始下一轮(y/n):  ");
  81.                                 start = input.next();       
  82.                         }
  83.                         /*显示结果*/
  84.                         showResult();                       
  85.                        
  86.                         // 循环游戏,直到退出系统
  87.                         System.out.print("\n要开始下一局吗?(y/n):");
  88.                         exit = input.next();                       
  89.                         System.out.println();
  90.                        
  91.                 }while(!exit.equals("n"));       
  92.                
  93.                 System.out.println("系统退出!");
  94.         }
  95.        
  96.         /**
  97.          * 显示比赛结果
  98.          */
  99.         public void showResult(){
  100.                 /*显示对战次数*/
  101.                 System.out.println("---------------------------------------------------");
  102.                 System.out.println(computer.name + "  VS  " + person.name);
  103.                 System.out.println("对战次数:"+ count);
  104.                
  105.                 // 显示最终的得分
  106.                 System.out.println("\n姓名\t得分");               
  107.                 System.out.println(person.name+"\t"+person.score);
  108.                 System.out.println(computer.name+"\t"+computer.score+"\n");
  109.                
  110.                
  111.                 /*显示对战结果*/
  112.                 int result = calcResult();
  113.                 if(result == 1){
  114.                         System.out.println("结果:打成平手,下次再和你一分高下!");
  115.                 }else if(result == 2){
  116.                         System.out.println("结果:恭喜恭喜!");   //用户获胜
  117.                 }else{
  118.                         System.out.println("结果:呵呵,笨笨,下次加油啊!");   //计算机获胜
  119.                 }
  120.                 System.out.println("---------------------------------------------------");
  121.         }
  122.        
  123.         /**
  124.          * 计算比赛结果
  125.          * @return 1:战平;2:用户赢;3:电脑赢
  126.          */
  127.     public int calcResult(){
  128.             if(person.score == computer.score){
  129.                       return 1; // 战平
  130.             }else if(person.score > computer.score){
  131.                       return 2; // 用户赢
  132.             }else{
  133.                       return 3; // 电脑赢
  134.             }
  135.            
  136.     }
  137. }
复制代码
  1. package com.game.guess;
  2. import java.util.Scanner;
  3. /**
  4. *
  5. * 玩家类
  6. */
  7. public class Person {
  8.       String name = "匿名";  // 名字
  9.       int score = 0;         // 积分  
  10.       
  11.       /**
  12.        * 出拳
  13.        * @return 出拳结果:1.剪刀 2.石头 3.布
  14.        */
  15.       public int showFist(){
  16.               // 接收用户的选择
  17.               Scanner input = new Scanner(System.in);
  18.               System.out.print("\n请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :");
  19.               int show = input.nextInt();
  20.               
  21.               // 输出出拳结果,并返回
  22.               switch(show){
  23.                   case 1:
  24.                           System.out.println("你出拳: 剪刀");
  25.                           break;
  26.                   case 2:
  27.                           System.out.println("你出拳: 石头");
  28.                           break;
  29.                   case 3:
  30.                           System.out.println("你出拳: 布");
  31.                           break;
  32.               }
  33.               return show;
  34.       }
  35. }
复制代码
  1. package com.game.guess;


  2. /**
  3. * 人机互动版猜拳游戏
  4. * 程序入口
  5. */
  6. public class StartGuess {
  7.         public static void main(String[] args) {
  8.                 Game game = new Game();
  9.                 game.startGame();
  10.         }
  11. }
复制代码
输出结果:
----------------欢 迎 进 入 游 戏 世 界----------------

                ******************
                **  猜拳, 开始    **
                ******************

出拳规则:1.剪刀 2.石头 3.布
请选择对方角色(1:刘备 2:孙权 3:曹操): 2
请输入你的姓名:康康
康康  VS  孙权  对战

要开始吗?(y/n) y

请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :2
你出拳: 石头
孙权出拳: 剪刀
结果: 恭喜, 你赢了!

是否开始下一轮(y/n):  y

请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :3
你出拳: 布
孙权出拳: 剪刀
结果说:^_^,你输了,真笨!


是否开始下一轮(y/n):  y

请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :2
你出拳: 石头
孙权出拳: 石头
结果:和局,真衰!嘿嘿,等着瞧吧 !


是否开始下一轮(y/n):  y

请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :1
你出拳: 剪刀
孙权出拳: 剪刀
结果:和局,真衰!嘿嘿,等着瞧吧 !


是否开始下一轮(y/n):  y

请出拳:1.剪刀 2.石头 3.布 (输入相应数字) :3
你出拳: 布
孙权出拳: 剪刀
结果说:^_^,你输了,真笨!


是否开始下一轮(y/n):  n
---------------------------------------------------
孙权  VS  康康
对战次数:5

姓名        得分
康康        1
孙权        2

结果:呵呵,笨笨,下次加油啊!
---------------------------------------------------

要开始下一局吗?(y/n):n

系统退出!

评分

参与人数 1技术分 +2 收起 理由
夜默 + 2 超时

查看全部评分

回复 使用道具 举报
亲雨泽回复:7楼,18楼,27楼,41楼,76楼,83楼,102楼,123楼,142楼

评分

参与人数 1技术分 +1 收起 理由
赵海洋 + 1 十题全答,加1

查看全部评分

回复 使用道具 举报
package RanDom;

import java.util.Scanner;
import java.util.Random;

public class GameDemo {
        public static void sop(Object obj)
        {
                System.out.println(obj);
        }
        public static void main(String[] Ags)
        {       
                sop("---------欢迎进入游戏世界---------");
                sop("");
                sop("");
                sop("*****************************");
                sop("         **猜拳开始**");
                sop("*****************************");
                sop("出拳规则:1 石头 2 剪刀 3 布 4 退出");
                sop("对战人物:1 修罗 2 地狱犬 3 啸月天狼 4 退出");
                sop("三局两胜制");
                sop("");
                sop("");
                sop("请输入对战人物:");
                Scanner in = new Scanner(System.in);
                int vs = in.nextInt();
                sop("请输入猜拳序号:");
                int get = in.nextInt();
                new Vs(vs,get).getNum();
        }
}
         class Vs {
        private int vs,get;
        Vs(int vs, int get)
        {
                this.vs = vs;
                this.get = get;
        }
        public void getNum()
        {
                if(vs==4||get==4)
                {
                        System.out.println("游戏结束!");
                }else if(vs<=0||vs>4||get<=0||get>4)
                {
                        System.out.println("数字输入错误!");
                }
                else if(vs==1)
                {
                        System.out.println("修罗与您对战,中途不给逃跑哦!");
                        new xiuLuo().VS(get);
                }
                else if(vs==2)
                {
                        System.out.println("地狱犬与您对战,中途不给逃跑哦!");
                        new dog(get);
                }
                else
                        System.out.println("啸月天狼与您对战,中途不给逃跑哦!");
                        new xiaoYue(get);
                }
       
        }
class xiuLuo {
        private int count1 = 0;//胜利
        private int count2 = 0;//平局
        private int count3 = 0;//失败
        private int x;
        private int y;
        xiuLuo(){}
        public void sop(Object obj)
        {
                System.out.println(obj);
        }
        public void VS(int get)
        {
                Scanner s = new Scanner(System.in);
                if(get==1)
                {
                        Random r = new Random();
                        x = r.nextInt(3)+1;
                        if(x==1)
                        {
                                sop("双方均为石头,平局");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束。");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count2;
                                VS(y);
                        }else if(x==2)
                        {
                                sop("我出了石头,对方出了剪刀,胜利!");
                               
                                if(count1==1)
                                {
                                        sop("恭喜游戏胜利!");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count1;
                                VS(y);
                        }
                        else if(x==3)
                        {
                                sop("我出了石头,对方出了布,失败!");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束。");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count3;
                                VS(y);
                        }
                }
                if(get==2)
                {
                        Random r = new Random();
                        x = r.nextInt(3)+1;
                        if(x==1)
                        {
                                sop("我出了剪刀,对方出了石头,失败!");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束。");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count3;
                                VS(y);
                        }else if(x==2)
                        {
                                sop("双方均为剪刀,平局!");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束!");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count2;
                                VS(y);
                        }
                        else if(x==3)
                        {
                                sop("我出了剪刀,对方出了布,胜利!");
                               
                                if(count1==1)
                                {
                                        sop("游戏胜利!");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count1;
                                VS(y);
                        }
                }
                if(get==3)
                {
                        Random r = new Random();
                        x = r.nextInt(3)+1;
                        if(x==1)
                        {
                                sop("我出了布,对方出了石头,胜利!");
                               
                                if(count1==1)
                                {
                                        sop("游戏胜利!");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count1;
                                VS(y);
                        }else if(x==2)
                        {
                                sop("我出了布,对方出了剪刀,失败!");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束!");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count3;
                                VS(y);
                        }
                        else if(x==3)
                        {
                                sop("双方均出了布,平局。");
                               
                                if((count1+count2+count3)==2)
                                {
                                        sop("次数达到上限,游戏结束。");
                                        System.exit(0);
                                }
                                sop("请输入猜拳序号:");
                                y = s.nextInt();
                                ++count2;
                                VS(y);
                        }
                }
        }
}
class dog extends xiuLuo{
        dog(int get)
        {
                super.VS(get);
        }
}
class xiaoYue extends xiuLuo{
        xiaoYue(int get)
        {
                super.VS(get);
        }
}
不知道该如何调整难度,就写了个简单点的

评分

参与人数 2技术分 +3 收起 理由
赵海洋 + 1 十题全答,加1
夜默 + 2

查看全部评分

回复 使用道具 举报
/*没有考虑难度问题*/
想的比较简单:
  1. <p>import java.util.Scanner;
  2. import java.util.Random;
  3. class Game{
  4.   public static void UI(){
  5.      System.out.println("--------欢迎进入游戏世界---------\n");
  6.      System.out.println("**********************************");
  7.      System.out.println("           **猜拳开始**           ");
  8.    System.out.println("**********************************\n");
  9.   }
  10.   public static String judge(int in,int random,int i){
  11.     if(in==random)
  12.      return "第"+i+"局平手";
  13. if((in==0&&random==1)||(in==1&&random==2)||(in==2&&random==0))//除了这3种情况外为lose
  14.   return "第"+i+"局你赢了";
  15. else
  16.    return "第"+i+"局你输了";
  17.   }
  18.   public static void main(String[] args){
  19.     UI();

  20. System.out.println("从键盘输入序号:1.石头 2.剪刀 3.布");  
  21.     String[] rule={" ","石头","剪刀","布"};
  22. Scanner scan=new Scanner(System.in);
  23. Random ran=new Random();
  24. int win=0,lose=2,ping=0;
  25. for(int i=0;i<3;++i){
  26.   //System.out.println("win="+win+" lose="+lose);</p><p>  System.out.println("第"+(i+1)+"局");

  27.   int in=scan.nextInt();
  28.   int random=ran.nextInt(3)+1;
  29.   System.out.println("你: "+rule[in]);
  30.      System.out.println("电脑: "+rule[random]);
  31.      String result=judge(in,random,i+1);
  32.   
  33.   if(result.equals("第"+(i+1)+"局你赢了")){
  34.    System.out.println(result);
  35.    ++win;
  36.    if(win==2)//胜两次判定胜利
  37.      break;
  38.   }
  39.      else
  40.     if(result.equals("第"+(i+1)+"局你输了")){
  41.         System.out.println(result);   
  42.      --lose;
  43.    if(lose==0)//输两次判定失败
  44.     break;
  45.     }
  46.     else{
  47.     System.out.println(result+"\n");
  48.     ++ping;
  49.     if(ping==2)//平两次判定平手
  50.      break;
  51.   }   
  52. }
  53.     /*对循环结果进行判断*/
  54. if(win==2)
  55.   System.out.println("你取得了最终胜利");
  56. else
  57.    if(lose==0)
  58.         System.out.println("你失败了");
  59.       else
  60.      System.out.println("你们平手了");
  61.   }
  62. }</p>
复制代码



评分

参与人数 1技术分 +2 收起 理由
夜默 + 2

查看全部评分

回复 使用道具 举报
  1. package project.select;
  2. import java.util.Arrays;
  3. import javax.swing.JOptionPane;
  4. import javax.swing.JScrollPane;
  5. import javax.swing.JTextArea;
  6. public class SelectLeader {


  7. public static void main(String[] args) {
  8. final String ino="1号:修罗;2号:地狱犬;3号:啸月天狼;4号:神秘人\n";
  9. final String rule="出拳规则:1.石头;2.剪刀;3.布 \n" +
  10. "请出拳";

  11. String[] candidate={"修罗","地狱犬","啸月天狼","神秘人"};
  12. //第一步:输入
  13. int[] students=new int[40];
  14. String input="";
  15. int sno=0;
  16. String prompt="";
  17. int count = 0;
  18. for(int i=0;i<3;i++){
  19. prompt="----------------欢迎进入游戏世界---------------\n";
  20. input=JOptionPane.showInputDialog(prompt+ino+rule);
  21. if(input!=null){//表明点击了取消键,表示放弃,此时数组元素值是0
  22. /* while循环处理用户输入的非有效数组的情况
  23. * (1)给出提示信息
  24. * (2)让用户重新输入*/
  25. while(!input.equals("1")&
  26. !input.equals("2")&
  27. !input.equals("3")){
  28. //给用户提示信息
  29. JOptionPane.showMessageDialog(null, "请输入有效数字!");
  30. //让用户重新输入
  31. input=JOptionPane.showInputDialog(prompt+ino+rule);
  32. //如果用户重新输入时,选择放弃,则通过break语句跳出while循环
  33. if(input==null){
  34. break;
  35. }
  36. }
  37. //由于while循环中,有break语句,所以此处要有条件判断
  38. if(input!=null){
  39. sno=Integer.parseInt(input);
  40. students=sno;
  41. }
  42. }


  43. }
  44. int n=random();
  45. int n1=Integer.parseInt(input);
  46. count=result11(n,n1,count);



  47. String result="游戏结果";
  48. result+="分为:"+count+"\n";
  49. if(count>=2){
  50. result+="您赢了";
  51. }else{
  52. result+= "您输了";
  53. }
  54. JTextArea jta=new JTextArea(20,30);//文本区对象
  55. jta.setText(result);//文本区对象的显示内容
  56. JScrollPane jsclp=new JScrollPane(jta);//给文本区添加滚动条
  57. JOptionPane.showMessageDialog(null, jsclp);
  58. System.out.println(count);

  59. }
  60. public static int result11(int n,int m,int count){
  61. if(n == m){
  62. System.out.println("平了");
  63. }else{
  64. if(m==1){
  65. if(n==2){
  66. JOptionPane.showMessageDialog(null,"你输了");
  67. }else if(n ==3){
  68. JOptionPane.showMessageDialog(null,"你赢了");
  69. count++;
  70. }
  71. }else if(m == 2) {
  72. if(n == 1){
  73. JOptionPane.showMessageDialog(null,"你赢了");
  74. count++;
  75. }else if(n ==3){
  76. JOptionPane.showMessageDialog(null,"你输了");
  77. }
  78. }else if( m ==3 ){
  79. if(n==1){
  80. JOptionPane.showMessageDialog(null,"你输了");
  81. }else if(n == 2){
  82. JOptionPane.showMessageDialog(null,"你赢了");
  83. count++;
  84. }
  85. }
  86. }
  87. return count;
  88. }
  89. public static int random() {
  90. int h = (int)(Math.random()*3+1);
  91. return h;
  92. }

  93. }代码题
复制代码
回复 使用道具 举报
本帖最后由 草貌路飞 于 2013-7-15 22:56 编辑

刚开始来晚了..前面的只做了三题
第一题:39楼  第二题:45楼  第四题:52楼  第五题:63楼  第六题:69楼  第七题:94楼  第八题:99楼  第九题:111楼  第十题:135楼


时间不够,还超了..只做了一种难度的情况,不好意思..
  1. package newpackge;

  2. import java.util.*;
  3. public class GameDemo
  4. {
  5.         private int difficulty = 0;
  6.         
  7.         public static void main(String[] args)
  8.         {
  9.                 GameDemo gd = new GameDemo();
  10.                 sop("-------欢迎进入游戏世界-------\t\n");
  11.                 sop("出拳规则:1.石头2.剪刀3.布");
  12.                 sop("对战人物:1.修罗2.地狱犬3.嘯月天狼4.神秘人");
  13.                 sop("        三局两胜制\t\n");
  14.                 sop("*************************");
  15.                 sop("       **猜拳开始**");
  16.                 sop("*************************\t\n");
  17.                
  18.                 Scanner sc = new Scanner(System.in);
  19.                 Random random = new Random(3);
  20.                
  21.                 sop_2("你选择什么难度?1.修罗2.地狱犬3.嘯月天狼4.神秘人  输入:");
  22.                 gd.difficulty = sc.nextInt();
  23.                
  24.                 int count = 0;
  25.                 int winCount = 0;
  26.                 int selection = 0;
  27.                 int selection_pc = 0;
  28.                 while(true)
  29.                 {
  30.                         if(3 == count)
  31.                         {
  32.                                 sop("\t");
  33.                                 if(winCount > 1)
  34.                                 {
  35.                                         sop("三次比赛最终结果是:你赢了!");
  36.                                 }
  37.                                 else
  38.                                 {
  39.                                         sop("三次比赛最终结果是:你输了!");
  40.                                 }
  41.                                 count = 0;
  42.                                 winCount = 0;
  43.                                 sop_2("继续游戏吗?1.继续2.结束  请输入:");
  44.                                 int temp = sc.nextInt();
  45.                                 if(temp == 1)
  46.                                 {
  47.                                         sop_2("你选择什么难度?1.修罗2.地狱犬3.嘯月天狼4.神秘人  输入:");
  48.                                         gd.difficulty = sc.nextInt();
  49.                                         continue;
  50.                                 }
  51.                                 if(temp == 2)
  52.                                 {
  53.                                         sop("byebye");
  54.                                         return;
  55.                                 }
  56.                                 else
  57.                                         sop("输入错误!byebye");
  58.                         }
  59.                         sop_2("你选择出什么?1.石头2.剪刀3.布  输入:");
  60.                         selection = sc.nextInt();
  61.                         
  62.                         if(gd.difficulty == 4)
  63.                         {
  64.                                 selection_pc = random.nextInt(3) + 1;
  65.                                 
  66.                         }
  67.                         if(selection == selection_pc)
  68.                         {
  69.                                 sop("电脑输出的也是:" + selection_pc);
  70.                                 continue;
  71.                         }
  72.                         else if(selection == 1 && selection - selection_pc == -1 || selection == 2 && selection - selection_pc == -1 || selection == 3 && selection- selection_pc == 2)
  73.                         {
  74.                                 sop("电脑输出的是:" + selection_pc);
  75.                                 sop("你赢了!");
  76.                                 winCount ++;
  77.                         }
  78.                         else
  79.                         {
  80.                                 sop("电脑输出的是:" + selection_pc);
  81.                                 sop("你输了!");
  82.                         }
  83.                         count ++;
  84.                 }
  85.         }
  86.         public static void sop(Object obj)
  87.         {
  88.                 System.out.println(obj);
  89.         }
  90.         public static void sop_2(Object obj)
  91.         {
  92.                 System.out.print(obj);
  93.         }
  94. }
复制代码
-------欢迎进入游戏世界-------        

出拳规则:1.石头2.剪刀3.布
对战人物:1.修罗2.地狱犬3.嘯月天狼4.神秘人
        三局两胜制        

*************************
       **猜拳开始**
*************************        

你选择什么难度?1.修罗2.地狱犬3.嘯月天狼4.神秘人  输入:4
你选择出什么?1.石头2.剪刀3.布  输入:1
电脑输出的是:3
你输了!
你选择出什么?1.石头2.剪刀3.布  输入:2
电脑输出的是:3
你赢了!
你选择出什么?1.石头2.剪刀3.布  输入:3
电脑输出的是:1
你赢了!
        
三次比赛最终结果是:你赢了!
继续游戏吗?1.继续2.结束  请输入:1
你选择什么难度?1.修罗2.地狱犬3.嘯月天狼4.神秘人  输入:4
你选择出什么?1.石头2.剪刀3.布  输入:3
电脑输出的是:2
你输了!
你选择出什么?1.石头2.剪刀3.布  输入:2
电脑输出的是:1
你输了!
你选择出什么?1.石头2.剪刀3.布  输入:1
电脑输出的也是:1
你选择出什么?1.石头2.剪刀3.布  输入:1
电脑输出的也是:1
你选择出什么?1.石头2.剪刀3.布  输入:1
电脑输出的是:2
你赢了!
        
三次比赛最终结果是:你输了!
继续游戏吗?1.继续2.结束  请输入:2
byebye

评分

参与人数 2技术分 +4 收起 理由
赵海洋 + 1 十题全答,加1
夜默 + 3

查看全部评分

回复 使用道具 举报
只赶上最后一题 在158楼
回复 使用道具 举报
运行结果
做完有点迟 斑竹不好意思啊  希望还算数

1.JPG (32.23 KB, 下载次数: 0)

1.JPG

2.JPG (32.39 KB, 下载次数: 0)

2.JPG

评分

参与人数 1技术分 +2 收起 理由
夜默 + 2

查看全部评分

回复 使用道具 举报
package com.ma.test;

import java.util.Scanner;

public class Person {
        int n = 0;

        public int input() {
                System.out.println("-------欢迎进入游戏世界--------");
                System.out.println("*******************************");
                System.out.println("        **猜拳开始** ");
                System.out.println("*******************************");
                System.out.println("出拳规则:石头,剪刀,布");
                System.out.println("你的对手为:1.修罗 2.地狱犬 3.啸月天狼 4.神秘人");
                System.out.println("三局两胜");
                System.out.println("*******************************");
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                if (s.equals("石头")) {
                        n = 1;
                } else if (s.equals("剪刀")) {
                        n = 2;
                } else if (s.equals("布")) {
                        n = 3;
                } else if (s.equals("exit")) {
                        System.out.print("系统退出了");
                        System.exit(0);
                }
                return n;
        }

        public static void main(String[] args) {
                while(true){   
                        Person p = new Person();
                        Computer c = new Computer();
                        Game g = new Game();   
                        g.result(p.input(), c.random());
                        }  
                }
        }



class Computer {
        public int random() {
                int h = (int) (Math.random() * 3 + 1);
                return h;
        }
}

class Game {
        public void result(int n, int m) {
                if (n == m) {
                        System.out.println("平了");
                } else {
                        if (m == 1) {
                                if (n == 2) {
                                        System.out.println("你输了");
                                } else if (n == 3) {
                                        System.out.println("你赢了");
                                }
                        } else if (m == 2) {
                                if (n == 1) {
                                        System.out.println("你赢了");
                                } else if (n == 3) {
                                        System.out.println("你输了");
                                }
                        } else if (m == 3) {
                                if (n == 1) {
                                        System.out.println("你输了");
                                } else if (n == 2) {
                                        System.out.println("你赢了");
                                }
                        }
                }
        }
}
回复 使用道具 举报
抢答题:8楼、11楼、26楼、29楼、60楼、72楼、96楼、108楼、126楼、137楼
代码提:169楼

评分

参与人数 1技术分 +1 收起 理由
赵海洋 + 1 十题全答,加1

查看全部评分

回复 使用道具 举报

本来刚好十点半,结果编辑了两下,过点了,应该可以的啦?:#
回复 使用道具 举报
我的强大在16、19、35、47、68、75、115、127、132、141楼,第一次参加抢答,认识到自己还是有很多不足,还得继续努力了,多谢楼主举行的活动,辛苦啦,加油!
代码题,尽力而为啦。

评分

参与人数 1技术分 +1 收起 理由
赵海洋 + 1 十题全答,加1

查看全部评分

回复 使用道具 举报
本帖最后由 阿凡提不买驴 于 2013-7-15 22:32 编辑
  1. import java.util.*;
  2. interface CaiQuan{
  3. public int caiQuan();
  4. public void caiQuanBegin();
  5. }
  6. class Person implements CaiQuan,Runnable{
  7. private String name;
  8. private int age;
  9. Person(String name,int age){
  10. this.name=name;
  11. this.age=age;
  12. }
  13. public String getName(){
  14. return this.name;
  15. }
  16. public int caiQuan(){
  17. Random r=new Random();
  18. int d=r.nextInt(3);
  19. return d;
  20. }
  21. public void caiQuanBegin(){
  22. String [] arr={"剪刀","石头","布"};
  23. int d=caiQuan();
  24. System.out.println(this.getName()+"出手:"+arr[d]);
  25. }
  26. public void run()throws IllegalThreadStateException{
  27. caiQuanBegin();
  28. }
  29. }
  30. class AnswerDemo{
  31. public static void main(String args[])throws IllegalThreadStateException, InterruptedException{
  32. Person person1=new Person("修罗",18);
  33. Person person2=new Person("地狱犬",20);
  34. Person person3=new Person("啸月天狼",22);
  35. System.out.println("开始游戏:");
  36. Thread d1=new Thread(person1);
  37. Thread d2=new Thread(person2);
  38. Thread d3=new Thread(person3);
  39. for(boolean b=true;b;){
  40. b=false;
  41. try{
  42. d1.start();
  43. d2.start();
  44. d3.start();
  45. }
  46. catch(IllegalThreadStateException e){
  47. throw new IllegalThreadStateException();
  48. }
  49. Thread.sleep(400);
  50. if((person1.caiQuan()==0 &&person1.caiQuan()==2 &&person3.caiQuan()==2)||(
  51. person1.caiQuan()==1 && person2.caiQuan()==0 &&person3.caiQuan()==0)||(person1.caiQuan()==2
  52. &&person2.caiQuan()==1 &&person3.caiQuan()==1)){
  53. System.out.println("修罗赢了,继续进行");
  54. break;
  55. }
  56. else{
  57. System.out.println("没有赢家,请重新开局");
  58. b=true;
  59. continue;
  60. }
  61. }
  62. }
  63. }
复制代码
感觉时间不太够用!

评分

参与人数 1技术分 +3 收起 理由
夜默 + 3

查看全部评分

回复 使用道具 举报
class Client {

public static void main(String[] args) throws IOException {
   String data;
   Socket client = null;
   BufferedReader inputs = null;
   BufferedReader key = null;
   PrintStream outputs = null;

   client = new Socket("localhost",6000);
   inputs = new BufferedReader(new InputStreamReader(client.getInputStream()));
   outputs = new PrintStream(client.getOutputStream());
   key = new BufferedReader(new InputStreamReader(System.in));
     
  

   while(true) {
   System.out.println("----------------------------");
   System.out.print("请出拳:石头/剪刀/布 ");
   data = key.readLine();
   outputs.println(data);
   System.out.println("ECHO: " + inputs.readLine());
          }
   

    }
}
楼层  3  14  25  53  65   78   81  103  120   143

评分

参与人数 2技术分 +1 黑马币 +6 收起 理由
赵海洋 + 1 十题全答,加1
夜默 + 6

查看全部评分

回复 使用道具 举报
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class caiquan{
  4.         final int jiandao=0;       
  5.         final int shitou=1;       
  6.         final int bu=2;               
  7.         public static void main(String[] args)        {
  8.                 String yn="y";               
  9.                 while (yn.equals("y"))    {
  10.                         Scanner  scanner = new Scanner(System.in);                 
  11.                         System.out.println("欢迎玩猜拳游戏。请输入0,1,2:0表示剪刀,1表示石头,2表示布");                 
  12.                         int a = scanner.nextInt();                                 
  13.                         Random rd = new Random();                 
  14.                         int b = rd.nextInt(3);                      
  15.                         switch (b)
  16.                         {             
  17.                         case 0:      
  18.                         {                
  19.                                 System.out.println("系统出的是剪刀");               
  20.                                 switch(a)                  
  21.                                 {                          
  22.                                 case 0:System.out.println("平");break;                          
  23.                                 case 1:System.out.println("赢");break;                          
  24.                                 case 2:System.out.println("输");break;                  
  25.                                
  26.                                 }        
  27.                                 }      
  28.                         break;        
  29.                         case 1:        
  30.                         {                  
  31.                                 System.out.println("系统出的是石头");                  
  32.                                 switch(a)                
  33.                                 {                        
  34.                                 case 0:System.out.println("输");break;                        
  35.                                 case 1:System.out.println("平");break;                        
  36.                                 case 2:System.out.println("赢");break;                
  37.                                 }        
  38.                                 }        
  39.                         break;        
  40.                         case 2:        
  41.                         {                
  42.                                 System.out.println("系统出的是布");                
  43.                                 switch(a)                
  44.                                 {                        
  45.                                 case 0:System.out.println("赢");break;                        
  46.                                 case 1:System.out.println("输");break;                        
  47.                                 case 2:System.out.println("平");break;                
  48.                                 }        
  49.                                 }      
  50.                         }      
  51.                         Scanner ynn = new Scanner(System.in);      
  52.                         System.out.println("是否继续?是请输入y,否则输入n。");      
  53.                         yn=ynn.next();   
  54.                         }       
  55.                 }
  56.         }
复制代码
欢迎玩猜拳游戏。请输入0,1,2:0表示剪刀,1表示石头,2表示布
1
系统出的是剪刀

是否继续?是请输入y,否则输入n。
y
欢迎玩猜拳游戏。请输入0,1,2:0表示剪刀,1表示石头,2表示布
0
系统出的是布

评分

参与人数 1技术分 +1 收起 理由
夜默 + 1

查看全部评分

回复 使用道具 举报
class PingTai extends Thread {
    String data;
    BufferedReader inputs;
    PrintStream outputs;
    Socket client;
  public PingTai(Socket socket) throws IOException {
        client = socket;
   
       inputs = new BufferedReader(new InputStreamReader(client.getInputStream()));
       outputs = new PrintStream(client.getOutputStream());
         
         
          this.start();}
         

     public void run() {
   
     while (true) {
        try {
                        data = inputs.readLine();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
       int res = (int) (Math.random() * 3);
       if (data == null)
          break;
        else {
      if (res == 0 && "石头".equals(data)) {
      data = "石头,打平了!!";
       } else if (res == 0 && "剪刀".equals(data)) {
      data = "石头,修罗赢了!!";
       } else if (res == 0 && "布".equals(data)) {
      data = "石头,你赢了!!";
       } else if (res == 1 && "石头".equals(data)) {
      data = "剪刀,你赢了!!";
       } else if (res == 1 && "剪刀".equals(data)) {
      data = "剪刀,打平了!!";
       } else if (res == 1 && "布".equals(data)) {
      data = "剪刀,修罗赢了!!";
       } else if (res == 2 && "石头".equals(data)) {
      data = "布,修罗赢了!!";
       } else if (res == 2 && "剪刀".equals(data)) {
      data = "布,你赢了!!";
       } else if (res == 2 && "布".equals(data)) {
      data = "布,打平了!!";
       } else {
      data = "修罗表示你在耍赖"; }
       outputs.println(data);
           }
       }
   
   try {
        client.close();
} catch (Exception e) {
        // TODO: handle exception
}
        
        
    }
}
回复 使用道具 举报
package cn.itcast.xiaoxian1;


import java.io.*;
import java.net.*;

public class FuWu extends Thread {
  ServerSocket server;
public FuWu() {
try {
       server = new ServerSocket(6000);
     }
      catch(IOException e) {
      System.exit(0);
     }
      this.start();
     }
public void run() {
   try   {
        while(true) {
        Socket client = server.accept();
        PingTai ss = new PingTai(client);
         }
      }
         catch(IOException e) {
           System.exit(1);
         }
      }
  public static void main(String[] args) {
               new FuWu();
        }
}
回复 使用道具 举报
错过了
回复 使用道具 举报
抢答题:地板,18,21,24,62,77,87,101,112,140

评分

参与人数 1技术分 +1 收起 理由
赵海洋 + 1 十题全答,加1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马