我是新手  修改了一点点  我感觉这样好点,嘿嘿
import java.util.*;
public class ki{
           public static void main(String[] args){
           Scanner in=new Scanner(System.in);
           System.out.println("-------猜拳游戏-------");
           System.out.println("1-剪刀,2-石头,3-布");
           int person=in.nextInt();
           int computer=(int)(Math.random()*3+1);
           String ="拳头";
           String 2="拳头";
           
        switch(person){
          case 1:
            ="剪刀";
            break;
            case 2:
            ="石头";
            break;
            case 3:
            ="布";         
            break;
            default:
            System.out.println();//加了个未知数
            
            
        }         switch(computer){
             case 1:
             2="剪刀";
          break;
             case 2:
             2="石头";
             break;
             case 3:
             2="布";
             break;
         
            
}                   if(computer==person)
   System.out.println("你出的是:"++",电脑出的是:"+2+",平局");
            else if
            (computer==1&&person==2&&computer==2&&person==3&&computer==3&&person==1)
System.out.println("你出的是:"++",电脑出的是:"+2+",你赢了");
            else if
            (computer==1&&person==3&&computer==2&&person==1&&computer==3&&person==2)
System.out.println("你出的是:"++",电脑出的是:"+2+",你输了");
else
System.out.println("你出的是未知数 请从新输入");



               }}

解决方案 »

  1.   

    最好做一个异常处理, 如果我输入的不是数字 而是其他的字节。 那么, 在你的程序中就会报错,
    修改后:如下!
     Scanner in=new Scanner(System.in);
             System.out.println("-------猜拳游戏-------");
             System.out.println("1-剪刀,2-石头,3-布");
             int person=0;
             try {
            person=in.nextInt();
    } catch (InputMismatchException e) {
    // TODO: handle exception
    System.err.println("请输入数字!");
    System.exit(0);

    }
             int computer=(int)(Math.random()*3+1);
             String ="拳头";
     String 2="拳头";
             
          switch(person){
           case 1:
              ="剪刀";
              break;
              case 2:
              ="石头";
              break;
              case 3:
              ="布";         
              break;
          }       switch(computer){
               case 1:
               2="剪刀";
           break;
               case 2:
               2="石头";
               break;
               case 3:
               2="布";
               break;
    }         
            if(computer==person){
              System.out.println("你出的是:"++",电脑出的是:"+2+",平局");}
               else if(computer==1&&person==2||computer==2&&person==3||computer==3&&person==1){
                System.out.println("你出的是:"++",电脑出的是:"+2+",你赢了");}
                  else
                 System.out.println("你出的是:"++",电脑出的是:"+2+",你输了");