| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2686 人关注过本帖
标题:已经试了无数遍,这个就是加不起来
只看楼主 加入收藏
mark191919
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
已经试了无数遍,这个就是加不起来
声明:本人中文退化。

package Assignments;

public class RockPaperScissorator {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        
        
        
        System.out.println("Welcome! Let’s Play Rock-Paper-Scissors!'");
        System.out.println("Remember:");
        System.out.println("Rock breaks Scissors, Paper covers Rock and Scissors cut Paper");
        System.out.println("");System.out.println("");System.out.println("");
        int p;
        do{
        int a,c,b;
        a=0;
        b=0;
        c=(int) (Math.random()*2+1);
        System.out.println("Ready?!");
        System.out.println("1. Rock");
        System.out.println("2. Paper");
        System.out.println("3. Scissors");
        System.out.println("Please choose your action: ");
        p=TextIO.getlnInt();
        do{
        if(p==1){
            if(c==1){System.out.println("Computer chose Rock!"); System.out.println("It’s a tie!"); a+=0;}
            if(c==2){System.out.println("Computer chose Scissors!");System.out.println("You win!");a+=1;}
            if(c==3){System.out.println("Computer chose Paper!");System.out.println("You lose!");a-=1;}
        }
        if(p==2){
            if(c==1){System.out.println("Computer chose Paper!'");System.out.println("It’s a tie!");a+=0;}
            if(c==2){System.out.println("Computer chose Rock!");System.out.println("You win!");a+=1;}
            if(c==3){System.out.println("Computer chose Scissors!");System.out.println("You lose!");a-=1;}
        }
        if(p==3){
            if(c==1){System.out.println("Computer chose Scissors!");System.out.println("It’s a tie!");a+=0;}
            if(c==2){System.out.println("Computer chose Paper!");System.out.println("You win!");a+=1;}
            if(c==3){System.out.println("Computer chose Rock!");System.out.println("You lose!");a-=1;}
                }}while(p<0);
        b+=1;   
        
        System.out.println("You have won "+a+" of "+b+" games.");
        }while(p%1==0||p>0);
    }

}


他最后呢应该是这个样子的:

Welcome! Let’s Play Rock-Paper-Scissors!
Remember:
Rock breaks Scissors, Paper covers Rock and Scissors cut Paper



Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 2

Computer chose Paper!
It’s a tie!
You have won 0 of 1 games.


Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 2

Computer chose Rock!
You win!
You have won 1 of 2 games.


Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 0

Goodbye!
You have won 1 of 2 games.

先别急,我还没加exit进去。。
我现在遇到的状况是这样的:
Welcome! Let’s Play Rock-Paper-Scissors!'
Remember:
Rock breaks Scissors, Paper covers Rock and Scissors cut Paper



Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
3
Computer chose Scissors!
It’s a tie!
You have won 0 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
1
Computer chose Rock!
It’s a tie!
You have won 0 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
2
Computer chose Rock!
You win!
You have won 1 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
2
Computer chose Rock!
You win!
You have won 1 of 1 games.

为毛一直是1啊。。。。。。。。。。。。。。
而且胜局也加不起来啊。。。。。。。。。。。。。
求解!!!!!!!!
搜索更多相关主题的帖子: Welcome package public method 中文 
2015-12-12 11:41
mark191919
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-12
收藏
得分:0 
为啥一个人也没有
2015-12-12 11:56
mark191919
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-12
收藏
得分:0 
。。。。。。。。。。。。。
2015-12-12 12:06
逆水寒刘
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:76
专家分:117
注 册:2013-3-27
收藏
得分:20 
 int a,c,b;
        a=0;
//这里你把b作为比赛局数,这应该是个全局变量。现在将b的声明提到第一个do的前面就可以了。
2015-12-12 16:16
S_dawn
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-1-2
收藏
得分:0 
c=(int) (Math.random()*2+1);是在[1,3)区间抽取整数
所以 c抽取的数不是1就是2  没有3的存在
2016-01-06 21:53
wh814574875
Rank: 1
等 级:新手上路
威 望:1
帖 子:4
专家分:3
注 册:2012-9-8
收藏
得分:0 
java的命名要规范些 这样大家看着也方便的
2016-01-11 12:37
快速回复:已经试了无数遍,这个就是加不起来
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029122 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved