标题:请问程序哪错了
只看楼主
X15810803158
Rank: 2
等 级:论坛游民
帖 子:49
专家分:36
注 册:2015-2-24
结帖率:91.67%
已结贴  问题点数:5 回复次数:3 
请问程序哪错了
import java.util.Scanner;
public class Q{
   public static void main(String[] args){
      Scanner s = new Scanner(System.in);
      System.out.println("------猜拳游戏------");
      System.out.println("请出拳:1:剪刀 2:石头 3:布");
      int person = s.nextIng();
      int computer = (int)(Math.random()*3)+1;
      String Mark = "头";//这是标记;
      String Mark2 = "头";
      
    switch (person){
             case 1:
             Mark = "剪刀";
             break;
             case 2:
             Mark = "石头";
             break;
             case 3:
             Mark = "布";
             break;
           }
           
      
           
   
   
   switch (person){
             case 1:
             Mark2 = "剪刀";
             break;
             case 2:
             Mark2 = "石头";
             break;
             case 3:
             Mark2 = "布";
             break;
           }
           
           
   if (person==computer){
      
              System.out.println("你出的是:"  +person    +"电脑出的是:"+computer +"平局");
            }
            else if (person==1&&computer==2||person==2&&computer==3||person==3&&computer==1){
               
                System.out.println("你出的是:"+person +"电脑出的是"  +computer+"你赢了");
               
               
            }else{
               
              System.out.println("你出的是:"+person+  "电脑出的是" +computer +"你输了");
               
           }   
           
           
           
           
           
   }



}
搜索更多相关主题的帖子: computer person public import 
2016-02-26 12:15
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:5 
程序代码:
switch (person)
{
    case 1:
    Mark = "剪刀";
    break;
    case 2:
    Mark = "石头";
    break;
    case 3:
    Mark = "布";
    break;
}
//computer
switch (computer)
{   
    case 1:
    Mark2 = "剪刀";
    break;
    case 2:
    Mark2 = "石头";
    break;
    case 3:
    Mark2 = "布";
    break;
} 

程序代码:
if (person==computer)
{    
    System.out.println("你出的是:"  + Mark + "电脑出的是:" + Mark2 + "平局");
}
else if ((person==1&&computer==3)||(person==2&&computer==1)||(person==3&&computer==2))  //逻辑搞错了吧
{              
    System.out.println("你出的是:"+ Mark + "电脑出的是" + Mark2 + "你赢了");                               
}
else
{             
    System.out.println("你出的是:"+ Mark + "电脑出的是" + Mark2 +"你输了");             
}


[此贴子已经被作者于2016-2-26 13:34编辑过]


   唯实惟新 至诚致志
2016-02-26 13:19
X15810803158
Rank: 2
等 级:论坛游民
帖 子:49
专家分:36
注 册:2015-2-24
得分:0 
回复 2楼 qq1023569223
编译错误   
        int person = s.nextIng();  //有误
2016-02-26 14:58
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
回复 3楼 X15810803158
int person = s.nextInt();  //nextIng???


[此贴子已经被作者于2016-2-26 15:13编辑过]


   唯实惟新 至诚致志
2016-02-26 15:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-461955-1-1.html




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

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