European gas test game -java

Java

Use what we've learned to do at a small project or a game, and so should more or less have a little bit of a sense of accomplishment, the following is the basics I learned to do crosswords game, and given to him ha ha ha soul. Interested parties can try to do some small game with a tool to improve their knowledge of what they will, or else your knowledge will not be so easy to digest is not it!

He may have the ability to rewrite more nice, put it as pseudo-code line ah!

Easy to use basic knowledge of the following are:

  • if
  • for
  • while
  • Random: randomly generated value, JDK classes package
  • Scanner: I'm not a description, you can see the official document, hey, or you can take a look at the JDK java API documentation, version 1.6.0 is the official Chinese version of the translation is not pheasant, another post download links to articles
/*
题目:固定一个随机数(1~100),然后猜出他
*/

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

public class demo02Scannersum {
    public static void main(String[] args) {
        Random r = new Random();
        int rr = r.nextInt(100) + 1;
        Scanner s = new Scanner(System.in);
        System.out.println("这是一个测试欧气的游戏,我会随机选取1~100的一个数,猜中它,次数用的越少的代表越欧");
        int result=1;
        while (true) {
            int ss = s.nextInt();
            if (rr > ss) {
                System.out.println("你的猜测小了哦!");
            } else if (rr < ss) {
                System.out.println("你的猜测大了哦!");
            }else{
                System.out.println("恭喜你猜中了哦,你一共猜了"+result+"次就猜中了哦!");
                break;
            }
            result++;
        }
        if (result<7) {
            System.out.println("恭喜你,你是一个特别欧的人");
        }else {
            System.out.println("看来你没有欧气,说不定还是一个非酋");
        }
    }
}

The result:
Please enter your guess to the value (1 to 100)
55
Your guess is big, oh!
33
Congratulations, you guessed it, oh, you guessed a total of 2 times to guess Oh!
Congratulations, you are a special person in Europe

No way I am is the case in Europe

Guess you like

Origin www.cnblogs.com/gz18221/p/11968497.html