中华考试网·阅读新闻
编程开发 > JAVA > 文章内容

JAVA编程入门教程(22)

2015-11-23编辑:guomu

实例;猜拳游戏

import java.util.Scanner;

public class Test{

       public static void main(String[] args){

              Scanner in=new Scanner(System.in);

              System.out.println("-------这是一个猜拳游戏-------");

              System.out.println("请出拳(1、石头 2、剪刀 3、布)");

              int people=in.nextInt();

              int computer=(int)(Math.random()*3)+1;

              System.out.println(people);

              String Marks="拳头";//这是做一个标记;

              String Marks2="拳头";//这是做另一个标记

              switch(people){

                     case 1:

                     Marks="石头";

                     break;

                     case 2:

                     Marks="剪刀";

                     break;

                     case 3:

                     Marks="布";

                     break;

              }

              switch(computer){

                     case 1:

                     Marks2="石头";

                     break;

                     case 2:

                     Marks2="剪刀";

                     break;

                     case 3:

                     Marks2="布";

                     break;

              }

              if(people==computer){

                     System.out.println("你出的是:"+Marks+"电脑出的是:"+Marks2+"%>_

JAVA编程入门教程(21)
咨询热线:4000-525-585(免长途费)